1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Internationalization and localisation for wxWidgets
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="wxPLURAL:1,2" options
37 // to extract the strings from the sources)
38 #ifndef WXINTL_NO_GETTEXT_MACRO
39 #define _(s) wxGetTranslation(_T(s))
40 #define wxPLURAL(sing, plur, n) wxGetTranslation(_T(sing), _T(plur), n)
43 // another one which just marks the strings for extraction, but doesn't
44 // perform the translation (use -kwxTRANSLATE with xgettext!)
45 #define wxTRANSLATE(str) _T(str)
47 // ----------------------------------------------------------------------------
49 // ----------------------------------------------------------------------------
51 class WXDLLIMPEXP_BASE wxLocale
;
52 class WXDLLIMPEXP_BASE wxLanguageInfoArray
;
55 // ============================================================================
57 // ============================================================================
59 // ----------------------------------------------------------------------------
60 // wxLanguage: defines all supported languages
61 // ----------------------------------------------------------------------------
63 // --- --- --- generated code begins here --- --- ---
65 // This enum is generated by misc/languages/genlang.py
66 // When making changes, please put them into misc/languages/langtabl.txt
69 // user's default/preffered language as got from OS:
71 // unknown language, if wxLocale::GetSystemLanguage fails:
80 wxLANGUAGE_ARABIC_ALGERIA
,
81 wxLANGUAGE_ARABIC_BAHRAIN
,
82 wxLANGUAGE_ARABIC_EGYPT
,
83 wxLANGUAGE_ARABIC_IRAQ
,
84 wxLANGUAGE_ARABIC_JORDAN
,
85 wxLANGUAGE_ARABIC_KUWAIT
,
86 wxLANGUAGE_ARABIC_LEBANON
,
87 wxLANGUAGE_ARABIC_LIBYA
,
88 wxLANGUAGE_ARABIC_MOROCCO
,
89 wxLANGUAGE_ARABIC_OMAN
,
90 wxLANGUAGE_ARABIC_QATAR
,
91 wxLANGUAGE_ARABIC_SAUDI_ARABIA
,
92 wxLANGUAGE_ARABIC_SUDAN
,
93 wxLANGUAGE_ARABIC_SYRIA
,
94 wxLANGUAGE_ARABIC_TUNISIA
,
95 wxLANGUAGE_ARABIC_UAE
,
96 wxLANGUAGE_ARABIC_YEMEN
,
101 wxLANGUAGE_AZERI_CYRILLIC
,
102 wxLANGUAGE_AZERI_LATIN
,
105 wxLANGUAGE_BELARUSIAN
,
111 wxLANGUAGE_BULGARIAN
,
113 wxLANGUAGE_CAMBODIAN
,
116 wxLANGUAGE_CHINESE_SIMPLIFIED
,
117 wxLANGUAGE_CHINESE_TRADITIONAL
,
118 wxLANGUAGE_CHINESE_HONGKONG
,
119 wxLANGUAGE_CHINESE_MACAU
,
120 wxLANGUAGE_CHINESE_SINGAPORE
,
121 wxLANGUAGE_CHINESE_TAIWAN
,
127 wxLANGUAGE_DUTCH_BELGIAN
,
129 wxLANGUAGE_ENGLISH_UK
,
130 wxLANGUAGE_ENGLISH_US
,
131 wxLANGUAGE_ENGLISH_AUSTRALIA
,
132 wxLANGUAGE_ENGLISH_BELIZE
,
133 wxLANGUAGE_ENGLISH_BOTSWANA
,
134 wxLANGUAGE_ENGLISH_CANADA
,
135 wxLANGUAGE_ENGLISH_CARIBBEAN
,
136 wxLANGUAGE_ENGLISH_DENMARK
,
137 wxLANGUAGE_ENGLISH_EIRE
,
138 wxLANGUAGE_ENGLISH_JAMAICA
,
139 wxLANGUAGE_ENGLISH_NEW_ZEALAND
,
140 wxLANGUAGE_ENGLISH_PHILIPPINES
,
141 wxLANGUAGE_ENGLISH_SOUTH_AFRICA
,
142 wxLANGUAGE_ENGLISH_TRINIDAD
,
143 wxLANGUAGE_ENGLISH_ZIMBABWE
,
144 wxLANGUAGE_ESPERANTO
,
151 wxLANGUAGE_FRENCH_BELGIAN
,
152 wxLANGUAGE_FRENCH_CANADIAN
,
153 wxLANGUAGE_FRENCH_LUXEMBOURG
,
154 wxLANGUAGE_FRENCH_MONACO
,
155 wxLANGUAGE_FRENCH_SWISS
,
160 wxLANGUAGE_GERMAN_AUSTRIAN
,
161 wxLANGUAGE_GERMAN_BELGIUM
,
162 wxLANGUAGE_GERMAN_LIECHTENSTEIN
,
163 wxLANGUAGE_GERMAN_LUXEMBOURG
,
164 wxLANGUAGE_GERMAN_SWISS
,
166 wxLANGUAGE_GREENLANDIC
,
172 wxLANGUAGE_HUNGARIAN
,
173 wxLANGUAGE_ICELANDIC
,
174 wxLANGUAGE_INDONESIAN
,
175 wxLANGUAGE_INTERLINGUA
,
176 wxLANGUAGE_INTERLINGUE
,
177 wxLANGUAGE_INUKTITUT
,
181 wxLANGUAGE_ITALIAN_SWISS
,
186 wxLANGUAGE_KASHMIRI_INDIA
,
189 wxLANGUAGE_KINYARWANDA
,
199 wxLANGUAGE_LITHUANIAN
,
200 wxLANGUAGE_MACEDONIAN
,
203 wxLANGUAGE_MALAYALAM
,
204 wxLANGUAGE_MALAY_BRUNEI_DARUSSALAM
,
205 wxLANGUAGE_MALAY_MALAYSIA
,
210 wxLANGUAGE_MOLDAVIAN
,
211 wxLANGUAGE_MONGOLIAN
,
214 wxLANGUAGE_NEPALI_INDIA
,
215 wxLANGUAGE_NORWEGIAN_BOKMAL
,
216 wxLANGUAGE_NORWEGIAN_NYNORSK
,
222 wxLANGUAGE_PORTUGUESE
,
223 wxLANGUAGE_PORTUGUESE_BRAZILIAN
,
226 wxLANGUAGE_RHAETO_ROMANCE
,
229 wxLANGUAGE_RUSSIAN_UKRAINE
,
233 wxLANGUAGE_SCOTS_GAELIC
,
235 wxLANGUAGE_SERBIAN_CYRILLIC
,
236 wxLANGUAGE_SERBIAN_LATIN
,
237 wxLANGUAGE_SERBO_CROATIAN
,
242 wxLANGUAGE_SINHALESE
,
245 wxLANGUAGE_SLOVENIAN
,
248 wxLANGUAGE_SPANISH_ARGENTINA
,
249 wxLANGUAGE_SPANISH_BOLIVIA
,
250 wxLANGUAGE_SPANISH_CHILE
,
251 wxLANGUAGE_SPANISH_COLOMBIA
,
252 wxLANGUAGE_SPANISH_COSTA_RICA
,
253 wxLANGUAGE_SPANISH_DOMINICAN_REPUBLIC
,
254 wxLANGUAGE_SPANISH_ECUADOR
,
255 wxLANGUAGE_SPANISH_EL_SALVADOR
,
256 wxLANGUAGE_SPANISH_GUATEMALA
,
257 wxLANGUAGE_SPANISH_HONDURAS
,
258 wxLANGUAGE_SPANISH_MEXICAN
,
259 wxLANGUAGE_SPANISH_MODERN
,
260 wxLANGUAGE_SPANISH_NICARAGUA
,
261 wxLANGUAGE_SPANISH_PANAMA
,
262 wxLANGUAGE_SPANISH_PARAGUAY
,
263 wxLANGUAGE_SPANISH_PERU
,
264 wxLANGUAGE_SPANISH_PUERTO_RICO
,
265 wxLANGUAGE_SPANISH_URUGUAY
,
266 wxLANGUAGE_SPANISH_US
,
267 wxLANGUAGE_SPANISH_VENEZUELA
,
268 wxLANGUAGE_SUNDANESE
,
271 wxLANGUAGE_SWEDISH_FINLAND
,
286 wxLANGUAGE_UKRAINIAN
,
288 wxLANGUAGE_URDU_INDIA
,
289 wxLANGUAGE_URDU_PAKISTAN
,
291 wxLANGUAGE_UZBEK_CYRILLIC
,
292 wxLANGUAGE_UZBEK_LATIN
,
293 wxLANGUAGE_VIETNAMESE
,
303 // for custom, user-defined languages:
304 wxLANGUAGE_USER_DEFINED
307 // --- --- --- generated code ends here --- --- ---
309 // ----------------------------------------------------------------------------
310 // wxLanguageInfo: encapsulates wxLanguage to OS native lang.desc.
311 // translation information
312 // ----------------------------------------------------------------------------
314 struct WXDLLIMPEXP_BASE wxLanguageInfo
316 int Language
; // wxLanguage id
317 wxString CanonicalName
; // Canonical name, e.g. fr_FR
319 wxUint32 WinLang
, // Win32 language identifiers
322 wxString Description
; // human-readable name of the language
325 // ----------------------------------------------------------------------------
326 // wxLocaleCategory: the category of locale settings
327 // ----------------------------------------------------------------------------
329 enum wxLocaleCategory
343 // ----------------------------------------------------------------------------
344 // wxLocaleInfo: the items understood by wxLocale::GetInfo()
345 // ----------------------------------------------------------------------------
349 // the thounsands separator
350 wxLOCALE_THOUSANDS_SEP
,
352 // the character used as decimal point
353 wxLOCALE_DECIMAL_POINT
357 // ----------------------------------------------------------------------------
358 // wxLocale: encapsulates all language dependent settings, including current
359 // message catalogs, date, time and currency formats (TODO) &c
360 // ----------------------------------------------------------------------------
362 enum wxLocaleInitFlags
364 wxLOCALE_LOAD_DEFAULT
= 0x0001, // load wxwin.mo?
365 wxLOCALE_CONV_ENCODING
= 0x0002 // convert encoding on the fly?
368 class WXDLLIMPEXP_BASE wxLocale
374 // call Init() if you use this ctor
375 wxLocale() { DoCommonInit(); }
377 // the ctor has a side effect of changing current locale
378 wxLocale(const wxChar
*szName
, // name (for messages)
379 const wxChar
*szShort
= (const wxChar
*) NULL
, // dir prefix (for msg files)
380 const wxChar
*szLocale
= (const wxChar
*) NULL
, // locale (for setlocale)
381 bool bLoadDefault
= true, // preload wxstd.mo?
382 bool bConvertEncoding
= false) // convert Win<->Unix if necessary?
386 Init(szName
, szShort
, szLocale
, bLoadDefault
, bConvertEncoding
);
389 wxLocale(int language
, // wxLanguage id or custom language
390 int flags
= wxLOCALE_LOAD_DEFAULT
| wxLOCALE_CONV_ENCODING
)
394 Init(language
, flags
);
397 // the same as a function (returns true on success)
398 bool Init(const wxChar
*szName
,
399 const wxChar
*szShort
= (const wxChar
*) NULL
,
400 const wxChar
*szLocale
= (const wxChar
*) NULL
,
401 bool bLoadDefault
= true,
402 bool bConvertEncoding
= false);
404 // same as second ctor (returns true on success)
405 bool Init(int language
= wxLANGUAGE_DEFAULT
,
406 int flags
= wxLOCALE_LOAD_DEFAULT
| wxLOCALE_CONV_ENCODING
);
408 // restores old locale
411 // Try to get user's (or OS's) preferred language setting.
412 // Return wxLANGUAGE_UNKNOWN if language-guessing algorithm failed
413 static int GetSystemLanguage();
415 // get the encoding used by default for text on this system, returns
416 // wxFONTENCODING_SYSTEM if it couldn't be determined
417 static wxFontEncoding
GetSystemEncoding();
419 // get the string describing the system encoding, return empty string if
420 // couldn't be determined
421 static wxString
GetSystemEncodingName();
423 // get the values of the given locale-dependent datum: the current locale
424 // is used, the US default value is returned if everything else fails
425 static wxString
GetInfo(wxLocaleInfo index
, wxLocaleCategory cat
);
427 // return true if the locale was set successfully
428 bool IsOk() const { return m_pszOldLocale
!= NULL
; }
430 // returns locale name
431 const wxChar
*GetLocale() const { return m_strLocale
; }
433 // return current locale wxLanguage value
434 int GetLanguage() const { return m_language
; }
436 // return locale name to be passed to setlocale()
437 wxString
GetSysName() const;
439 // return 'canonical' name, i.e. in the form of xx[_YY], where xx is
440 // language code according to ISO 639 and YY is country name
441 // as specified by ISO 3166.
442 wxString
GetCanonicalName() const { return m_strShort
; }
444 // add a prefix to the catalog lookup path: the message catalog files will be
445 // looked up under prefix/<lang>/LC_MESSAGES, prefix/LC_MESSAGES and prefix
448 // This only applies to subsequent invocations of AddCatalog()!
449 static void AddCatalogLookupPathPrefix(const wxString
& prefix
);
451 // add a catalog: it's searched for in standard places (current directory
452 // first, system one after), but the you may prepend additional directories to
453 // the search path with AddCatalogLookupPathPrefix().
455 // The loaded catalog will be used for message lookup by GetString().
457 // Returns 'true' if it was successfully loaded
458 bool AddCatalog(const wxChar
*szDomain
);
459 bool AddCatalog(const wxChar
*szDomain
,
460 wxLanguage msgIdLanguage
, const wxChar
*msgIdCharset
);
462 // check if the given catalog is loaded
463 bool IsLoaded(const wxChar
*szDomain
) const;
465 // Retrieve the language info struct for the given language
467 // Returns NULL if no info found, pointer must *not* be deleted by caller
468 static const wxLanguageInfo
*GetLanguageInfo(int lang
);
470 // Returns language name in English or empty string if the language
471 // is not in database
472 static wxString
GetLanguageName(int lang
);
474 // Find the language for the given locale string which may be either a
475 // canonical ISO 2 letter language code ("xx"), a language code followed by
476 // the country code ("xx_XX") or a Windows full language name ("Xxxxx...")
478 // Returns NULL if no info found, pointer must *not* be deleted by caller
479 static const wxLanguageInfo
*FindLanguageInfo(const wxString
& locale
);
481 // Add custom language to the list of known languages.
482 // Notes: 1) wxLanguageInfo contains platform-specific data
483 // 2) must be called before Init to have effect
484 static void AddLanguage(const wxLanguageInfo
& info
);
486 // retrieve the translation for a string in all loaded domains unless
487 // the szDomain parameter is specified (and then only this domain is
489 // n - additional parameter for PluralFormsParser
491 // return original string if translation is not available
492 // (in this case an error message is generated the first time
493 // a string is not found; use wxLogNull to suppress it)
495 // domains are searched in the last to first order, i.e. catalogs
496 // added later override those added before.
497 const wxChar
*GetString(const wxChar
*szOrigString
,
498 const wxChar
*szDomain
= NULL
) const;
499 // plural form version of the same:
500 const wxChar
*GetString(const wxChar
*szOrigString
,
501 const wxChar
*szOrigString2
,
503 const wxChar
*szDomain
= NULL
) const;
505 // Returns the current short name for the locale
506 const wxString
& GetName() const { return m_strShort
; }
508 // return the contents of .po file header
509 wxString
GetHeaderValue( const wxChar
* szHeader
,
510 const wxChar
* szDomain
= NULL
) const;
512 // These two methods are for internal use only. First one creates
513 // ms_languagesDB if it doesn't already exist, second one destroys
515 static void CreateLanguagesDB();
516 static void DestroyLanguagesDB();
519 // find catalog by name in a linked list, return NULL if !found
520 wxMsgCatalog
*FindCatalog(const wxChar
*szDomain
) const;
522 // copy default table of languages from global static array to
523 // m_langugagesInfo, called by InitLanguagesDB
524 static void InitLanguagesDB();
526 // initialize the member fields to default values
529 wxString m_strLocale
, // this locale name
530 m_strShort
; // short name for the locale
531 int m_language
; // this locale wxLanguage value
533 const wxChar
*m_pszOldLocale
; // previous locale from setlocale()
534 wxLocale
*m_pOldLocale
; // previous wxLocale
536 wxMsgCatalog
*m_pMsgCat
; // pointer to linked list of catalogs
538 bool m_bConvertEncoding
;
542 static wxLanguageInfoArray
*ms_languagesDB
;
544 DECLARE_NO_COPY_CLASS(wxLocale
)
547 // ----------------------------------------------------------------------------
549 // ----------------------------------------------------------------------------
551 // get the current locale object (note that it may be NULL!)
552 extern WXDLLIMPEXP_BASE wxLocale
* wxGetLocale();
554 // get the translation of the string in the current locale
555 inline const wxChar
*wxGetTranslation(const wxChar
*sz
)
557 wxLocale
*pLoc
= wxGetLocale();
559 return pLoc
->GetString(sz
);
563 inline const wxChar
*wxGetTranslation(const wxChar
*sz1
, const wxChar
*sz2
,
566 wxLocale
*pLoc
= wxGetLocale();
568 return pLoc
->GetString(sz1
, sz2
, n
);
570 return n
== 1 ? sz1
: sz2
;
575 // the macros should still be defined - otherwise compilation would fail
577 #if !defined(WXINTL_NO_GETTEXT_MACRO)
583 #define wxTRANSLATE(str) _T(str)
585 // Note: use of 'inline' here can cause this symbol not to be found when compiled with gcc
586 //const wxChar *wxGetTranslation(const wxChar *sz);
587 #define wxGetTranslation(sz) (sz)
589 #endif // wxUSE_INTL/!wxUSE_INTL
591 // define this one just in case it occurs somewhere (instead of preferred
593 #if !defined(WXINTL_NO_GETTEXT_MACRO)
594 #if !defined(gettext_noop)
595 #define gettext_noop(str) _T(str)
602 #endif // _WX_INTL_H_