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 /////////////////////////////////////////////////////////////////////////////
13 // WARNING: Parts of this file are generated. See misc/languages/README for
20 #include "wx/string.h"
22 // Make wxLayoutDirection enum available without need for wxUSE_INTL so wxWindow, wxApp
23 // and other classes are not distrubed by wxUSE_INTL
25 enum wxLayoutDirection
34 #include "wx/fontenc.h"
36 // ============================================================================
38 // ============================================================================
40 // ----------------------------------------------------------------------------
42 // ----------------------------------------------------------------------------
44 // gettext() style macros (notice that xgettext should be invoked with
45 // --keyword="_" --keyword="wxPLURAL:1,2" options
46 // to extract the strings from the sources)
47 #ifndef WXINTL_NO_GETTEXT_MACRO
48 #define _(s) wxGetTranslation((s))
49 #define wxPLURAL(sing, plur, n) wxGetTranslation((sing), (plur), n)
52 // another one which just marks the strings for extraction, but doesn't
53 // perform the translation (use -kwxTRANSLATE with xgettext!)
54 #define wxTRANSLATE(str) str
56 // ----------------------------------------------------------------------------
58 // ----------------------------------------------------------------------------
60 class WXDLLIMPEXP_FWD_BASE wxLocale
;
61 class WXDLLIMPEXP_FWD_BASE wxLanguageInfoArray
;
64 // ============================================================================
66 // ============================================================================
68 // ----------------------------------------------------------------------------
69 // wxLanguage: defines all supported languages
70 // ----------------------------------------------------------------------------
72 // --- --- --- generated code begins here --- --- ---
74 // This enum is generated by misc/languages/genlang.py
75 // When making changes, please put them into misc/languages/langtabl.txt
78 // user's default/preffered language as got from OS:
80 // unknown language, if wxLocale::GetSystemLanguage fails:
89 wxLANGUAGE_ARABIC_ALGERIA
,
90 wxLANGUAGE_ARABIC_BAHRAIN
,
91 wxLANGUAGE_ARABIC_EGYPT
,
92 wxLANGUAGE_ARABIC_IRAQ
,
93 wxLANGUAGE_ARABIC_JORDAN
,
94 wxLANGUAGE_ARABIC_KUWAIT
,
95 wxLANGUAGE_ARABIC_LEBANON
,
96 wxLANGUAGE_ARABIC_LIBYA
,
97 wxLANGUAGE_ARABIC_MOROCCO
,
98 wxLANGUAGE_ARABIC_OMAN
,
99 wxLANGUAGE_ARABIC_QATAR
,
100 wxLANGUAGE_ARABIC_SAUDI_ARABIA
,
101 wxLANGUAGE_ARABIC_SUDAN
,
102 wxLANGUAGE_ARABIC_SYRIA
,
103 wxLANGUAGE_ARABIC_TUNISIA
,
104 wxLANGUAGE_ARABIC_UAE
,
105 wxLANGUAGE_ARABIC_YEMEN
,
110 wxLANGUAGE_AZERI_CYRILLIC
,
111 wxLANGUAGE_AZERI_LATIN
,
114 wxLANGUAGE_BELARUSIAN
,
120 wxLANGUAGE_BULGARIAN
,
122 wxLANGUAGE_CAMBODIAN
,
125 wxLANGUAGE_CHINESE_SIMPLIFIED
,
126 wxLANGUAGE_CHINESE_TRADITIONAL
,
127 wxLANGUAGE_CHINESE_HONGKONG
,
128 wxLANGUAGE_CHINESE_MACAU
,
129 wxLANGUAGE_CHINESE_SINGAPORE
,
130 wxLANGUAGE_CHINESE_TAIWAN
,
136 wxLANGUAGE_DUTCH_BELGIAN
,
138 wxLANGUAGE_ENGLISH_UK
,
139 wxLANGUAGE_ENGLISH_US
,
140 wxLANGUAGE_ENGLISH_AUSTRALIA
,
141 wxLANGUAGE_ENGLISH_BELIZE
,
142 wxLANGUAGE_ENGLISH_BOTSWANA
,
143 wxLANGUAGE_ENGLISH_CANADA
,
144 wxLANGUAGE_ENGLISH_CARIBBEAN
,
145 wxLANGUAGE_ENGLISH_DENMARK
,
146 wxLANGUAGE_ENGLISH_EIRE
,
147 wxLANGUAGE_ENGLISH_JAMAICA
,
148 wxLANGUAGE_ENGLISH_NEW_ZEALAND
,
149 wxLANGUAGE_ENGLISH_PHILIPPINES
,
150 wxLANGUAGE_ENGLISH_SOUTH_AFRICA
,
151 wxLANGUAGE_ENGLISH_TRINIDAD
,
152 wxLANGUAGE_ENGLISH_ZIMBABWE
,
153 wxLANGUAGE_ESPERANTO
,
160 wxLANGUAGE_FRENCH_BELGIAN
,
161 wxLANGUAGE_FRENCH_CANADIAN
,
162 wxLANGUAGE_FRENCH_LUXEMBOURG
,
163 wxLANGUAGE_FRENCH_MONACO
,
164 wxLANGUAGE_FRENCH_SWISS
,
169 wxLANGUAGE_GERMAN_AUSTRIAN
,
170 wxLANGUAGE_GERMAN_BELGIUM
,
171 wxLANGUAGE_GERMAN_LIECHTENSTEIN
,
172 wxLANGUAGE_GERMAN_LUXEMBOURG
,
173 wxLANGUAGE_GERMAN_SWISS
,
175 wxLANGUAGE_GREENLANDIC
,
181 wxLANGUAGE_HUNGARIAN
,
182 wxLANGUAGE_ICELANDIC
,
183 wxLANGUAGE_INDONESIAN
,
184 wxLANGUAGE_INTERLINGUA
,
185 wxLANGUAGE_INTERLINGUE
,
186 wxLANGUAGE_INUKTITUT
,
190 wxLANGUAGE_ITALIAN_SWISS
,
195 wxLANGUAGE_KASHMIRI_INDIA
,
198 wxLANGUAGE_KINYARWANDA
,
208 wxLANGUAGE_LITHUANIAN
,
209 wxLANGUAGE_MACEDONIAN
,
212 wxLANGUAGE_MALAYALAM
,
213 wxLANGUAGE_MALAY_BRUNEI_DARUSSALAM
,
214 wxLANGUAGE_MALAY_MALAYSIA
,
219 wxLANGUAGE_MOLDAVIAN
,
220 wxLANGUAGE_MONGOLIAN
,
223 wxLANGUAGE_NEPALI_INDIA
,
224 wxLANGUAGE_NORWEGIAN_BOKMAL
,
225 wxLANGUAGE_NORWEGIAN_NYNORSK
,
231 wxLANGUAGE_PORTUGUESE
,
232 wxLANGUAGE_PORTUGUESE_BRAZILIAN
,
235 wxLANGUAGE_RHAETO_ROMANCE
,
238 wxLANGUAGE_RUSSIAN_UKRAINE
,
243 wxLANGUAGE_SCOTS_GAELIC
,
245 wxLANGUAGE_SERBIAN_CYRILLIC
,
246 wxLANGUAGE_SERBIAN_LATIN
,
247 wxLANGUAGE_SERBO_CROATIAN
,
252 wxLANGUAGE_SINHALESE
,
255 wxLANGUAGE_SLOVENIAN
,
258 wxLANGUAGE_SPANISH_ARGENTINA
,
259 wxLANGUAGE_SPANISH_BOLIVIA
,
260 wxLANGUAGE_SPANISH_CHILE
,
261 wxLANGUAGE_SPANISH_COLOMBIA
,
262 wxLANGUAGE_SPANISH_COSTA_RICA
,
263 wxLANGUAGE_SPANISH_DOMINICAN_REPUBLIC
,
264 wxLANGUAGE_SPANISH_ECUADOR
,
265 wxLANGUAGE_SPANISH_EL_SALVADOR
,
266 wxLANGUAGE_SPANISH_GUATEMALA
,
267 wxLANGUAGE_SPANISH_HONDURAS
,
268 wxLANGUAGE_SPANISH_MEXICAN
,
269 wxLANGUAGE_SPANISH_MODERN
,
270 wxLANGUAGE_SPANISH_NICARAGUA
,
271 wxLANGUAGE_SPANISH_PANAMA
,
272 wxLANGUAGE_SPANISH_PARAGUAY
,
273 wxLANGUAGE_SPANISH_PERU
,
274 wxLANGUAGE_SPANISH_PUERTO_RICO
,
275 wxLANGUAGE_SPANISH_URUGUAY
,
276 wxLANGUAGE_SPANISH_US
,
277 wxLANGUAGE_SPANISH_VENEZUELA
,
278 wxLANGUAGE_SUNDANESE
,
281 wxLANGUAGE_SWEDISH_FINLAND
,
296 wxLANGUAGE_UKRAINIAN
,
298 wxLANGUAGE_URDU_INDIA
,
299 wxLANGUAGE_URDU_PAKISTAN
,
301 wxLANGUAGE_UZBEK_CYRILLIC
,
302 wxLANGUAGE_UZBEK_LATIN
,
303 wxLANGUAGE_VALENCIAN
,
304 wxLANGUAGE_VIETNAMESE
,
314 // for custom, user-defined languages:
315 wxLANGUAGE_USER_DEFINED
318 // --- --- --- generated code ends here --- --- ---
320 // ----------------------------------------------------------------------------
321 // wxLanguageInfo: encapsulates wxLanguage to OS native lang.desc.
322 // translation information
323 // ----------------------------------------------------------------------------
325 struct WXDLLIMPEXP_BASE wxLanguageInfo
327 int Language
; // wxLanguage id
328 wxString CanonicalName
; // Canonical name, e.g. fr_FR
330 wxUint32 WinLang
, // Win32 language identifiers
333 wxString Description
; // human-readable name of the language
334 wxLayoutDirection LayoutDirection
;
337 // return the LCID corresponding to this language
338 wxUint32
GetLCID() const;
341 // return the locale name corresponding to this language usable with
342 // setlocale() on the current system
343 wxString
GetLocaleName() const;
346 // for Unix systems GetLocaleName() is trivial so implement it inline here, for
347 // MSW it's implemented in intl.cpp
349 inline wxString
wxLanguageInfo::GetLocaleName() const { return CanonicalName
; }
352 // ----------------------------------------------------------------------------
353 // wxLocaleCategory: the category of locale settings
354 // ----------------------------------------------------------------------------
356 enum wxLocaleCategory
370 // ----------------------------------------------------------------------------
371 // wxLocaleInfo: the items understood by wxLocale::GetInfo()
372 // ----------------------------------------------------------------------------
376 // the thounsands separator
377 wxLOCALE_THOUSANDS_SEP
,
379 // the character used as decimal point
380 wxLOCALE_DECIMAL_POINT
384 // ----------------------------------------------------------------------------
385 // wxLocale: encapsulates all language dependent settings, including current
386 // message catalogs, date, time and currency formats (TODO) &c
387 // ----------------------------------------------------------------------------
389 enum wxLocaleInitFlags
391 wxLOCALE_LOAD_DEFAULT
= 0x0001, // load wxwin.mo?
392 wxLOCALE_CONV_ENCODING
= 0x0002 // convert encoding on the fly?
395 class WXDLLIMPEXP_BASE wxLocale
401 // call Init() if you use this ctor
402 wxLocale() { DoCommonInit(); }
404 // the ctor has a side effect of changing current locale
405 wxLocale(const wxString
& name
, // name (for messages)
406 const wxString
& shortName
= wxEmptyString
, // dir prefix (for msg files)
407 const wxString
& locale
= wxEmptyString
, // locale (for setlocale)
408 bool bLoadDefault
= true, // preload wxstd.mo?
409 bool bConvertEncoding
= false) // convert Win<->Unix if necessary?
413 Init(name
, shortName
, locale
, bLoadDefault
, bConvertEncoding
);
416 wxLocale(int language
, // wxLanguage id or custom language
417 int flags
= wxLOCALE_LOAD_DEFAULT
| wxLOCALE_CONV_ENCODING
)
421 Init(language
, flags
);
424 // the same as a function (returns true on success)
425 bool Init(const wxString
& name
,
426 const wxString
& shortName
= wxEmptyString
,
427 const wxString
& locale
= wxEmptyString
,
428 bool bLoadDefault
= true,
429 bool bConvertEncoding
= false);
431 // same as second ctor (returns true on success)
432 bool Init(int language
= wxLANGUAGE_DEFAULT
,
433 int flags
= wxLOCALE_LOAD_DEFAULT
| wxLOCALE_CONV_ENCODING
);
435 // restores old locale
438 // Try to get user's (or OS's) preferred language setting.
439 // Return wxLANGUAGE_UNKNOWN if language-guessing algorithm failed
440 static int GetSystemLanguage();
442 // get the encoding used by default for text on this system, returns
443 // wxFONTENCODING_SYSTEM if it couldn't be determined
444 static wxFontEncoding
GetSystemEncoding();
446 // get the string describing the system encoding, return empty string if
447 // couldn't be determined
448 static wxString
GetSystemEncodingName();
450 // get the values of the given locale-dependent datum: the current locale
451 // is used, the US default value is returned if everything else fails
452 static wxString
GetInfo(wxLocaleInfo index
, wxLocaleCategory cat
);
454 // return true if the locale was set successfully
455 bool IsOk() const { return m_pszOldLocale
!= NULL
; }
457 // returns locale name
458 const wxString
& GetLocale() const { return m_strLocale
; }
460 // return current locale wxLanguage value
461 int GetLanguage() const { return m_language
; }
463 // return locale name to be passed to setlocale()
464 wxString
GetSysName() const;
466 // return 'canonical' name, i.e. in the form of xx[_YY], where xx is
467 // language code according to ISO 639 and YY is country name
468 // as specified by ISO 3166.
469 wxString
GetCanonicalName() const { return m_strShort
; }
471 // add a prefix to the catalog lookup path: the message catalog files will be
472 // looked up under prefix/<lang>/LC_MESSAGES, prefix/LC_MESSAGES and prefix
475 // This only applies to subsequent invocations of AddCatalog()!
476 static void AddCatalogLookupPathPrefix(const wxString
& prefix
);
478 // add a catalog: it's searched for in standard places (current directory
479 // first, system one after), but the you may prepend additional directories to
480 // the search path with AddCatalogLookupPathPrefix().
482 // The loaded catalog will be used for message lookup by GetString().
484 // Returns 'true' if it was successfully loaded
485 bool AddCatalog(const wxString
& domain
);
486 bool AddCatalog(const wxString
& domain
,
487 wxLanguage msgIdLanguage
, const wxString
& msgIdCharset
);
489 // check if the given locale is provided by OS and C run time
490 static bool IsAvailable(int lang
);
492 // check if the given catalog is loaded
493 bool IsLoaded(const wxString
& domain
) const;
495 // Retrieve the language info struct for the given language
497 // Returns NULL if no info found, pointer must *not* be deleted by caller
498 static const wxLanguageInfo
*GetLanguageInfo(int lang
);
500 // Returns language name in English or empty string if the language
501 // is not in database
502 static wxString
GetLanguageName(int lang
);
504 // Find the language for the given locale string which may be either a
505 // canonical ISO 2 letter language code ("xx"), a language code followed by
506 // the country code ("xx_XX") or a Windows full language name ("Xxxxx...")
508 // Returns NULL if no info found, pointer must *not* be deleted by caller
509 static const wxLanguageInfo
*FindLanguageInfo(const wxString
& locale
);
511 // Add custom language to the list of known languages.
512 // Notes: 1) wxLanguageInfo contains platform-specific data
513 // 2) must be called before Init to have effect
514 static void AddLanguage(const wxLanguageInfo
& info
);
516 // retrieve the translation for a string in all loaded domains unless
517 // the szDomain parameter is specified (and then only this domain is
519 // n - additional parameter for PluralFormsParser
521 // return original string if translation is not available
522 // (in this case an error message is generated the first time
523 // a string is not found; use wxLogNull to suppress it)
525 // domains are searched in the last to first order, i.e. catalogs
526 // added later override those added before.
527 virtual const wxString
& GetString(const wxString
& origString
,
528 const wxString
& domain
= wxEmptyString
) const;
529 // plural form version of the same:
530 virtual const wxString
& GetString(const wxString
& origString
,
531 const wxString
& origString2
,
533 const wxString
& domain
= wxEmptyString
) const;
535 // this is hack to work around a problem with wxGetTranslation() which
536 // returns const wxString& and not wxString, so when it returns untranslated
537 // string, it needs to have a copy of it somewhere
538 static const wxString
& GetUntranslatedString(const wxString
& str
);
540 // Returns the current short name for the locale
541 const wxString
& GetName() const { return m_strShort
; }
543 // return the contents of .po file header
544 wxString
GetHeaderValue(const wxString
& header
,
545 const wxString
& domain
= wxEmptyString
) const;
547 // These two methods are for internal use only. First one creates
548 // ms_languagesDB if it doesn't already exist, second one destroys
550 static void CreateLanguagesDB();
551 static void DestroyLanguagesDB();
554 // find catalog by name in a linked list, return NULL if !found
555 wxMsgCatalog
*FindCatalog(const wxString
& domain
) const;
557 // copy default table of languages from global static array to
558 // m_langugagesInfo, called by InitLanguagesDB
559 static void InitLanguagesDB();
561 // initialize the member fields to default values
564 wxString m_strLocale
, // this locale name
565 m_strShort
; // short name for the locale
566 int m_language
; // this locale wxLanguage value
568 const char *m_pszOldLocale
; // previous locale from setlocale()
569 wxLocale
*m_pOldLocale
; // previous wxLocale
571 wxMsgCatalog
*m_pMsgCat
; // pointer to linked list of catalogs
573 bool m_bConvertEncoding
;
577 static wxLanguageInfoArray
*ms_languagesDB
;
579 DECLARE_NO_COPY_CLASS(wxLocale
)
582 // ----------------------------------------------------------------------------
584 // ----------------------------------------------------------------------------
586 // get the current locale object (note that it may be NULL!)
587 extern WXDLLIMPEXP_BASE wxLocale
* wxGetLocale();
589 // get the translation of the string in the current locale
590 inline const wxString
& wxGetTranslation(const wxString
& str
,
591 const wxString
& domain
= wxEmptyString
)
593 wxLocale
*pLoc
= wxGetLocale();
595 return pLoc
->GetString(str
, domain
);
597 // NB: this function returns reference to a string, so we have to keep
598 // a copy of it somewhere
599 return wxLocale::GetUntranslatedString(str
);
601 inline const wxString
& wxGetTranslation(const wxString
& str1
,
602 const wxString
& str2
,
604 const wxString
& domain
= wxEmptyString
)
606 wxLocale
*pLoc
= wxGetLocale();
608 return pLoc
->GetString(str1
, str2
, n
, domain
);
610 // NB: this function returns reference to a string, so we have to keep
611 // a copy of it somewhere
613 ? wxLocale::GetUntranslatedString(str1
)
614 : wxLocale::GetUntranslatedString(str2
);
619 // the macros should still be defined - otherwise compilation would fail
621 #if !defined(WXINTL_NO_GETTEXT_MACRO)
625 #define wxPLURAL(sing, plur, n) ((n) == 1 ? (sing) : (plur))
628 #define wxTRANSLATE(str) str
630 // NB: we use a template here in order to avoid using
631 // wxLocale::GetUntranslatedString() above, which would be required if
632 // we returned const wxString&; this way, the compiler should be able to
633 // optimize wxGetTranslation() away
635 template<typename TString
>
636 inline TString
wxGetTranslation(TString str
)
639 template<typename TString
, typename TDomain
>
640 inline TString
wxGetTranslation(TString str
, TDomain
WXUNUSED(domain
))
643 template<typename TString
, typename TDomain
>
644 inline TString
wxGetTranslation(TString str1
, TString str2
, size_t n
)
645 { return n
== 1 ? str1
: str2
; }
647 template<typename TString
, typename TDomain
>
648 inline TString
wxGetTranslation(TString str1
, TString str2
, size_t n
,
649 TDomain
WXUNUSED(domain
))
650 { return n
== 1 ? str1
: str2
; }
652 #endif // wxUSE_INTL/!wxUSE_INTL
654 // define this one just in case it occurs somewhere (instead of preferred
656 #if !defined(WXINTL_NO_GETTEXT_MACRO)
657 #if !defined(gettext_noop)
658 #define gettext_noop(str) (str)
665 #endif // _WX_INTL_H_