1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Internationalization and localisation for wxWindows
4 // Author: Vadim Zeitlin
5 // Modified by: Michael N. Filippov <michael@idisys.iae.nsk.su>
6 // (2003/09/30 - plural forms support)
9 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
16 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
17 #pragma interface "intl.h"
21 #include "wx/string.h"
25 #include "wx/fontenc.h"
27 // ============================================================================
29 // ============================================================================
31 // ----------------------------------------------------------------------------
33 // ----------------------------------------------------------------------------
35 // gettext() style macros (notice that xgettext should be invoked with
36 // --keyword="_" --keyword="wxGetTranslation:1,2" options
37 // to extract the strings from the sources)
38 #ifndef WXINTL_NO_GETTEXT_MACRO
39 #define _(s) wxGetTranslation(_T(s))
42 // another one which just marks the strings for extraction, but doesn't
43 // perform the translation (use -kwxTRANSLATE with xgettext!)
44 #define wxTRANSLATE(str) _T(str)
46 // ----------------------------------------------------------------------------
48 // ----------------------------------------------------------------------------
50 class WXDLLIMPEXP_BASE wxLocale
;
51 class WXDLLIMPEXP_BASE wxMsgCatalog
;
52 class WXDLLIMPEXP_BASE wxLanguageInfoArray
;
54 // ============================================================================
56 // ============================================================================
58 // ----------------------------------------------------------------------------
59 // wxLanguage: defines all supported languages
60 // ----------------------------------------------------------------------------
62 // --- --- --- generated code begins here --- --- ---
64 // This enum is generated by misc/languages/genlang.py
65 // When making changes, please put them into misc/languages/langtabl.txt
68 // user's default/preffered language as got from OS:
70 // unknown language, if wxLocale::GetSystemLanguage fails:
79 wxLANGUAGE_ARABIC_ALGERIA
,
80 wxLANGUAGE_ARABIC_BAHRAIN
,
81 wxLANGUAGE_ARABIC_EGYPT
,
82 wxLANGUAGE_ARABIC_IRAQ
,
83 wxLANGUAGE_ARABIC_JORDAN
,
84 wxLANGUAGE_ARABIC_KUWAIT
,
85 wxLANGUAGE_ARABIC_LEBANON
,
86 wxLANGUAGE_ARABIC_LIBYA
,
87 wxLANGUAGE_ARABIC_MOROCCO
,
88 wxLANGUAGE_ARABIC_OMAN
,
89 wxLANGUAGE_ARABIC_QATAR
,
90 wxLANGUAGE_ARABIC_SAUDI_ARABIA
,
91 wxLANGUAGE_ARABIC_SUDAN
,
92 wxLANGUAGE_ARABIC_SYRIA
,
93 wxLANGUAGE_ARABIC_TUNISIA
,
94 wxLANGUAGE_ARABIC_UAE
,
95 wxLANGUAGE_ARABIC_YEMEN
,
100 wxLANGUAGE_AZERI_CYRILLIC
,
101 wxLANGUAGE_AZERI_LATIN
,
104 wxLANGUAGE_BELARUSIAN
,
110 wxLANGUAGE_BULGARIAN
,
112 wxLANGUAGE_CAMBODIAN
,
115 wxLANGUAGE_CHINESE_SIMPLIFIED
,
116 wxLANGUAGE_CHINESE_TRADITIONAL
,
117 wxLANGUAGE_CHINESE_HONGKONG
,
118 wxLANGUAGE_CHINESE_MACAU
,
119 wxLANGUAGE_CHINESE_SINGAPORE
,
120 wxLANGUAGE_CHINESE_TAIWAN
,
126 wxLANGUAGE_DUTCH_BELGIAN
,
128 wxLANGUAGE_ENGLISH_UK
,
129 wxLANGUAGE_ENGLISH_US
,
130 wxLANGUAGE_ENGLISH_AUSTRALIA
,
131 wxLANGUAGE_ENGLISH_BELIZE
,
132 wxLANGUAGE_ENGLISH_BOTSWANA
,
133 wxLANGUAGE_ENGLISH_CANADA
,
134 wxLANGUAGE_ENGLISH_CARIBBEAN
,
135 wxLANGUAGE_ENGLISH_DENMARK
,
136 wxLANGUAGE_ENGLISH_EIRE
,
137 wxLANGUAGE_ENGLISH_JAMAICA
,
138 wxLANGUAGE_ENGLISH_NEW_ZEALAND
,
139 wxLANGUAGE_ENGLISH_PHILIPPINES
,
140 wxLANGUAGE_ENGLISH_SOUTH_AFRICA
,
141 wxLANGUAGE_ENGLISH_TRINIDAD
,
142 wxLANGUAGE_ENGLISH_ZIMBABWE
,
143 wxLANGUAGE_ESPERANTO
,
150 wxLANGUAGE_FRENCH_BELGIAN
,
151 wxLANGUAGE_FRENCH_CANADIAN
,
152 wxLANGUAGE_FRENCH_LUXEMBOURG
,
153 wxLANGUAGE_FRENCH_MONACO
,
154 wxLANGUAGE_FRENCH_SWISS
,
159 wxLANGUAGE_GERMAN_AUSTRIAN
,
160 wxLANGUAGE_GERMAN_BELGIUM
,
161 wxLANGUAGE_GERMAN_LIECHTENSTEIN
,
162 wxLANGUAGE_GERMAN_LUXEMBOURG
,
163 wxLANGUAGE_GERMAN_SWISS
,
165 wxLANGUAGE_GREENLANDIC
,
171 wxLANGUAGE_HUNGARIAN
,
172 wxLANGUAGE_ICELANDIC
,
173 wxLANGUAGE_INDONESIAN
,
174 wxLANGUAGE_INTERLINGUA
,
175 wxLANGUAGE_INTERLINGUE
,
176 wxLANGUAGE_INUKTITUT
,
180 wxLANGUAGE_ITALIAN_SWISS
,
185 wxLANGUAGE_KASHMIRI_INDIA
,
188 wxLANGUAGE_KINYARWANDA
,
198 wxLANGUAGE_LITHUANIAN
,
199 wxLANGUAGE_MACEDONIAN
,
202 wxLANGUAGE_MALAYALAM
,
203 wxLANGUAGE_MALAY_BRUNEI_DARUSSALAM
,
204 wxLANGUAGE_MALAY_MALAYSIA
,
209 wxLANGUAGE_MOLDAVIAN
,
210 wxLANGUAGE_MONGOLIAN
,
213 wxLANGUAGE_NEPALI_INDIA
,
214 wxLANGUAGE_NORWEGIAN_BOKMAL
,
215 wxLANGUAGE_NORWEGIAN_NYNORSK
,
221 wxLANGUAGE_PORTUGUESE
,
222 wxLANGUAGE_PORTUGUESE_BRAZILIAN
,
225 wxLANGUAGE_RHAETO_ROMANCE
,
228 wxLANGUAGE_RUSSIAN_UKRAINE
,
232 wxLANGUAGE_SCOTS_GAELIC
,
234 wxLANGUAGE_SERBIAN_CYRILLIC
,
235 wxLANGUAGE_SERBIAN_LATIN
,
236 wxLANGUAGE_SERBO_CROATIAN
,
241 wxLANGUAGE_SINHALESE
,
244 wxLANGUAGE_SLOVENIAN
,
247 wxLANGUAGE_SPANISH_ARGENTINA
,
248 wxLANGUAGE_SPANISH_BOLIVIA
,
249 wxLANGUAGE_SPANISH_CHILE
,
250 wxLANGUAGE_SPANISH_COLOMBIA
,
251 wxLANGUAGE_SPANISH_COSTA_RICA
,
252 wxLANGUAGE_SPANISH_DOMINICAN_REPUBLIC
,
253 wxLANGUAGE_SPANISH_ECUADOR
,
254 wxLANGUAGE_SPANISH_EL_SALVADOR
,
255 wxLANGUAGE_SPANISH_GUATEMALA
,
256 wxLANGUAGE_SPANISH_HONDURAS
,
257 wxLANGUAGE_SPANISH_MEXICAN
,
258 wxLANGUAGE_SPANISH_MODERN
,
259 wxLANGUAGE_SPANISH_NICARAGUA
,
260 wxLANGUAGE_SPANISH_PANAMA
,
261 wxLANGUAGE_SPANISH_PARAGUAY
,
262 wxLANGUAGE_SPANISH_PERU
,
263 wxLANGUAGE_SPANISH_PUERTO_RICO
,
264 wxLANGUAGE_SPANISH_URUGUAY
,
265 wxLANGUAGE_SPANISH_US
,
266 wxLANGUAGE_SPANISH_VENEZUELA
,
267 wxLANGUAGE_SUNDANESE
,
270 wxLANGUAGE_SWEDISH_FINLAND
,
285 wxLANGUAGE_UKRAINIAN
,
287 wxLANGUAGE_URDU_INDIA
,
288 wxLANGUAGE_URDU_PAKISTAN
,
290 wxLANGUAGE_UZBEK_CYRILLIC
,
291 wxLANGUAGE_UZBEK_LATIN
,
292 wxLANGUAGE_VIETNAMESE
,
302 // for custom, user-defined languages:
303 wxLANGUAGE_USER_DEFINED
306 // --- --- --- generated code ends here --- --- ---
308 // ----------------------------------------------------------------------------
309 // wxLanguageInfo: encapsulates wxLanguage to OS native lang.desc.
310 // translation information
311 // ----------------------------------------------------------------------------
313 struct WXDLLIMPEXP_BASE wxLanguageInfo
315 int Language
; // wxLanguage id
316 wxString CanonicalName
; // Canonical name, e.g. fr_FR
318 wxUint32 WinLang
, // Win32 language identifiers
321 wxString Description
; // human-readable name of the language
324 // ----------------------------------------------------------------------------
325 // wxLocaleCategory: the category of locale settings
326 // ----------------------------------------------------------------------------
328 enum wxLocaleCategory
342 // ----------------------------------------------------------------------------
343 // wxLocaleInfo: the items understood by wxLocale::GetInfo()
344 // ----------------------------------------------------------------------------
348 // the thounsands separator
349 wxLOCALE_THOUSANDS_SEP
,
351 // the character used as decimal point
352 wxLOCALE_DECIMAL_POINT
356 // ----------------------------------------------------------------------------
357 // wxLocale: encapsulates all language dependent settings, including current
358 // message catalogs, date, time and currency formats (TODO) &c
359 // ----------------------------------------------------------------------------
361 enum wxLocaleInitFlags
363 wxLOCALE_LOAD_DEFAULT
= 0x0001, // load wxwin.mo?
364 wxLOCALE_CONV_ENCODING
= 0x0002 // convert encoding on the fly?
367 class WXDLLIMPEXP_BASE wxLocale
373 // call Init() if you use this ctor
375 // the ctor has a side effect of changing current locale
376 wxLocale(const wxChar
*szName
, // name (for messages)
377 const wxChar
*szShort
= (const wxChar
*) NULL
, // dir prefix (for msg files)
378 const wxChar
*szLocale
= (const wxChar
*) NULL
, // locale (for setlocale)
379 bool bLoadDefault
= TRUE
, // preload wxstd.mo?
380 bool bConvertEncoding
= FALSE
) // convert Win<->Unix if neccessary?
382 Init(szName
, szShort
, szLocale
, bLoadDefault
, bConvertEncoding
);
385 wxLocale(int language
, // wxLanguage id or custom language
386 int flags
= wxLOCALE_LOAD_DEFAULT
| wxLOCALE_CONV_ENCODING
)
387 { Init(language
, flags
); }
389 // the same as a function (returns TRUE on success)
390 bool Init(const wxChar
*szName
,
391 const wxChar
*szShort
= (const wxChar
*) NULL
,
392 const wxChar
*szLocale
= (const wxChar
*) NULL
,
393 bool bLoadDefault
= TRUE
,
394 bool bConvertEncoding
= FALSE
);
396 // same as second ctor (returns TRUE on success)
397 bool Init(int language
= wxLANGUAGE_DEFAULT
,
398 int flags
= wxLOCALE_LOAD_DEFAULT
| wxLOCALE_CONV_ENCODING
);
400 // restores old locale
403 // Try to get user's (or OS's) prefered language setting.
404 // Return wxLANGUAGE_UNKNOWN if language-guessing algorithm failed
405 static int GetSystemLanguage();
407 // get the encoding used by default for text on this system, returns
408 // wxFONTENCODING_SYSTEM if it couldn't be determined
409 static wxFontEncoding
GetSystemEncoding();
411 // get the string describing the system encoding, return empty string if
412 // couldn't be determined
413 static wxString
GetSystemEncodingName();
415 // get the values of the given locale-dependent datum: the current locale
416 // is used, the US default value is returned if everything else fails
417 static wxString
GetInfo(wxLocaleInfo index
, wxLocaleCategory cat
);
419 // return TRUE if the locale was set successfully
420 bool IsOk() const { return m_pszOldLocale
!= NULL
; }
422 // returns locale name
423 const wxChar
*GetLocale() const { return m_strLocale
; }
425 // return current locale wxLanguage value
426 int GetLanguage() const { return m_language
; }
428 // return locale name to be passed to setlocale()
429 wxString
GetSysName() const;
431 // return 'canonical' name, i.e. in the form of xx[_YY], where xx is
432 // language code according to ISO 639 and YY is country name
433 // as specified by ISO 3166.
434 wxString
GetCanonicalName() const { return m_strShort
; }
436 // add a prefix to the catalog lookup path: the message catalog files will be
437 // looked up under prefix/<lang>/LC_MESSAGES, prefix/LC_MESSAGES and prefix
440 // This only applies to subsequent invocations of AddCatalog()!
441 static void AddCatalogLookupPathPrefix(const wxString
& prefix
);
443 // add a catalog: it's searched for in standard places (current directory
444 // first, system one after), but the you may prepend additional directories to
445 // the search path with AddCatalogLookupPathPrefix().
447 // The loaded catalog will be used for message lookup by GetString().
449 // Returns 'true' if it was successfully loaded
450 bool AddCatalog(const wxChar
*szDomain
);
452 // check if the given catalog is loaded
453 bool IsLoaded(const wxChar
*szDomain
) const;
455 // Retrieve the language info struct for the given language
457 // Returns NULL if no info found, pointer must *not* be deleted by caller
458 static const wxLanguageInfo
*GetLanguageInfo(int lang
);
460 // Returns language name in English or empty string if the language
461 // is not in database
462 static wxString
GetLanguageName(int lang
);
464 // Find the language for the given locale string which may be either a
465 // canonical ISO 2 letter language code ("xx"), a language code followed by
466 // the country code ("xx_XX") or a Windows full language name ("Xxxxx...")
468 // Returns NULL if no info found, pointer must *not* be deleted by caller
469 static const wxLanguageInfo
*FindLanguageInfo(const wxString
& locale
);
471 // Add custom language to the list of known languages.
472 // Notes: 1) wxLanguageInfo contains platform-specific data
473 // 2) must be called before Init to have effect
474 static void AddLanguage(const wxLanguageInfo
& info
);
476 // retrieve the translation for a string in all loaded domains unless
477 // the szDomain parameter is specified (and then only this domain is
479 // n - additional parameter for PluralFormsParser
481 // return original string if translation is not available
482 // (in this case an error message is generated the first time
483 // a string is not found; use wxLogNull to suppress it)
485 // domains are searched in the last to first order, i.e. catalogs
486 // added later override those added before.
487 const wxChar
*GetString(const wxChar
*szOrigString
,
488 const wxChar
*szDomain
= (const wxChar
*) NULL
) const;
489 // plural form version of the same:
490 const wxChar
*GetString(const wxChar
*szOrigString
,
491 const wxChar
*szOrigString2
,
493 const wxChar
*szDomain
= (const wxChar
*) NULL
) const;
495 // Returns the current short name for the locale
496 const wxString
& GetName() const { return m_strShort
; }
498 // These two methods are for internal use only. First one creates
499 // ms_languagesDB if it doesn't already exist, second one destroys
501 static void CreateLanguagesDB();
502 static void DestroyLanguagesDB();
505 // find catalog by name in a linked list, return NULL if !found
506 wxMsgCatalog
*FindCatalog(const wxChar
*szDomain
) const;
508 // copy default table of languages from global static array to
509 // m_langugagesInfo, called by InitLanguagesDB
510 static void InitLanguagesDB();
512 wxString m_strLocale
, // this locale name
513 m_strShort
; // short name for the locale
514 int m_language
; // this locale wxLanguage value
516 const wxChar
*m_pszOldLocale
; // previous locale from setlocale()
517 wxLocale
*m_pOldLocale
; // previous wxLocale
519 wxMsgCatalog
*m_pMsgCat
; // pointer to linked list of catalogs
521 bool m_bConvertEncoding
;
525 static wxLanguageInfoArray
*ms_languagesDB
;
527 DECLARE_NO_COPY_CLASS(wxLocale
)
530 // ----------------------------------------------------------------------------
532 // ----------------------------------------------------------------------------
534 // get the current locale object (note that it may be NULL!)
535 extern WXDLLIMPEXP_BASE wxLocale
* wxGetLocale();
537 // get the translation of the string in the current locale
538 inline const wxChar
*wxGetTranslation(const wxChar
*sz
)
540 wxLocale
*pLoc
= wxGetLocale();
542 return pLoc
->GetString(sz
);
546 inline const wxChar
*wxGetTranslation(const wxChar
*sz1
, const wxChar
*sz2
,
549 wxLocale
*pLoc
= wxGetLocale();
551 return pLoc
->GetString(sz1
, sz2
, n
);
553 return n
== 1 ? sz1
: sz2
;
558 // the macros should still be defined - otherwise compilation would fail
560 #if !defined(WXINTL_NO_GETTEXT_MACRO)
566 #define wxTRANSLATE(str) _T(str)
568 // Note: use of 'inline' here can cause this symbol not to be found when compiled with gcc
569 //const wxChar *wxGetTranslation(const wxChar *sz);
570 #define wxGetTranslation(sz) (sz)
572 #endif // wxUSE_INTL/!wxUSE_INTL
574 // define this one just in case it occurs somewhere (instead of preferred
576 #if !defined(WXINTL_NO_GETTEXT_MACRO)
577 #if !defined(gettext_noop)
578 #define gettext_noop(str) _T(str)
585 #endif // _WX_INTL_H_