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 --- --- ---
75 The languages supported by wxLocale.
77 This enum is generated by misc/languages/genlang.py
78 When making changes, please put them into misc/languages/langtabl.txt
82 /// User's default/preffered language as got from OS.
85 /// Unknown language, returned if wxLocale::GetSystemLanguage fails.
94 wxLANGUAGE_ARABIC_ALGERIA
,
95 wxLANGUAGE_ARABIC_BAHRAIN
,
96 wxLANGUAGE_ARABIC_EGYPT
,
97 wxLANGUAGE_ARABIC_IRAQ
,
98 wxLANGUAGE_ARABIC_JORDAN
,
99 wxLANGUAGE_ARABIC_KUWAIT
,
100 wxLANGUAGE_ARABIC_LEBANON
,
101 wxLANGUAGE_ARABIC_LIBYA
,
102 wxLANGUAGE_ARABIC_MOROCCO
,
103 wxLANGUAGE_ARABIC_OMAN
,
104 wxLANGUAGE_ARABIC_QATAR
,
105 wxLANGUAGE_ARABIC_SAUDI_ARABIA
,
106 wxLANGUAGE_ARABIC_SUDAN
,
107 wxLANGUAGE_ARABIC_SYRIA
,
108 wxLANGUAGE_ARABIC_TUNISIA
,
109 wxLANGUAGE_ARABIC_UAE
,
110 wxLANGUAGE_ARABIC_YEMEN
,
116 wxLANGUAGE_AZERI_CYRILLIC
,
117 wxLANGUAGE_AZERI_LATIN
,
120 wxLANGUAGE_BELARUSIAN
,
126 wxLANGUAGE_BULGARIAN
,
128 wxLANGUAGE_CAMBODIAN
,
131 wxLANGUAGE_CHINESE_SIMPLIFIED
,
132 wxLANGUAGE_CHINESE_TRADITIONAL
,
133 wxLANGUAGE_CHINESE_HONGKONG
,
134 wxLANGUAGE_CHINESE_MACAU
,
135 wxLANGUAGE_CHINESE_SINGAPORE
,
136 wxLANGUAGE_CHINESE_TAIWAN
,
142 wxLANGUAGE_DUTCH_BELGIAN
,
144 wxLANGUAGE_ENGLISH_UK
,
145 wxLANGUAGE_ENGLISH_US
,
146 wxLANGUAGE_ENGLISH_AUSTRALIA
,
147 wxLANGUAGE_ENGLISH_BELIZE
,
148 wxLANGUAGE_ENGLISH_BOTSWANA
,
149 wxLANGUAGE_ENGLISH_CANADA
,
150 wxLANGUAGE_ENGLISH_CARIBBEAN
,
151 wxLANGUAGE_ENGLISH_DENMARK
,
152 wxLANGUAGE_ENGLISH_EIRE
,
153 wxLANGUAGE_ENGLISH_JAMAICA
,
154 wxLANGUAGE_ENGLISH_NEW_ZEALAND
,
155 wxLANGUAGE_ENGLISH_PHILIPPINES
,
156 wxLANGUAGE_ENGLISH_SOUTH_AFRICA
,
157 wxLANGUAGE_ENGLISH_TRINIDAD
,
158 wxLANGUAGE_ENGLISH_ZIMBABWE
,
159 wxLANGUAGE_ESPERANTO
,
166 wxLANGUAGE_FRENCH_BELGIAN
,
167 wxLANGUAGE_FRENCH_CANADIAN
,
168 wxLANGUAGE_FRENCH_LUXEMBOURG
,
169 wxLANGUAGE_FRENCH_MONACO
,
170 wxLANGUAGE_FRENCH_SWISS
,
175 wxLANGUAGE_GERMAN_AUSTRIAN
,
176 wxLANGUAGE_GERMAN_BELGIUM
,
177 wxLANGUAGE_GERMAN_LIECHTENSTEIN
,
178 wxLANGUAGE_GERMAN_LUXEMBOURG
,
179 wxLANGUAGE_GERMAN_SWISS
,
181 wxLANGUAGE_GREENLANDIC
,
187 wxLANGUAGE_HUNGARIAN
,
188 wxLANGUAGE_ICELANDIC
,
189 wxLANGUAGE_INDONESIAN
,
190 wxLANGUAGE_INTERLINGUA
,
191 wxLANGUAGE_INTERLINGUE
,
192 wxLANGUAGE_INUKTITUT
,
196 wxLANGUAGE_ITALIAN_SWISS
,
201 wxLANGUAGE_KASHMIRI_INDIA
,
204 wxLANGUAGE_KINYARWANDA
,
214 wxLANGUAGE_LITHUANIAN
,
215 wxLANGUAGE_MACEDONIAN
,
218 wxLANGUAGE_MALAYALAM
,
219 wxLANGUAGE_MALAY_BRUNEI_DARUSSALAM
,
220 wxLANGUAGE_MALAY_MALAYSIA
,
225 wxLANGUAGE_MOLDAVIAN
,
226 wxLANGUAGE_MONGOLIAN
,
229 wxLANGUAGE_NEPALI_INDIA
,
230 wxLANGUAGE_NORWEGIAN_BOKMAL
,
231 wxLANGUAGE_NORWEGIAN_NYNORSK
,
237 wxLANGUAGE_PORTUGUESE
,
238 wxLANGUAGE_PORTUGUESE_BRAZILIAN
,
241 wxLANGUAGE_RHAETO_ROMANCE
,
244 wxLANGUAGE_RUSSIAN_UKRAINE
,
249 wxLANGUAGE_SCOTS_GAELIC
,
251 wxLANGUAGE_SERBIAN_CYRILLIC
,
252 wxLANGUAGE_SERBIAN_LATIN
,
253 wxLANGUAGE_SERBO_CROATIAN
,
258 wxLANGUAGE_SINHALESE
,
261 wxLANGUAGE_SLOVENIAN
,
264 wxLANGUAGE_SPANISH_ARGENTINA
,
265 wxLANGUAGE_SPANISH_BOLIVIA
,
266 wxLANGUAGE_SPANISH_CHILE
,
267 wxLANGUAGE_SPANISH_COLOMBIA
,
268 wxLANGUAGE_SPANISH_COSTA_RICA
,
269 wxLANGUAGE_SPANISH_DOMINICAN_REPUBLIC
,
270 wxLANGUAGE_SPANISH_ECUADOR
,
271 wxLANGUAGE_SPANISH_EL_SALVADOR
,
272 wxLANGUAGE_SPANISH_GUATEMALA
,
273 wxLANGUAGE_SPANISH_HONDURAS
,
274 wxLANGUAGE_SPANISH_MEXICAN
,
275 wxLANGUAGE_SPANISH_MODERN
,
276 wxLANGUAGE_SPANISH_NICARAGUA
,
277 wxLANGUAGE_SPANISH_PANAMA
,
278 wxLANGUAGE_SPANISH_PARAGUAY
,
279 wxLANGUAGE_SPANISH_PERU
,
280 wxLANGUAGE_SPANISH_PUERTO_RICO
,
281 wxLANGUAGE_SPANISH_URUGUAY
,
282 wxLANGUAGE_SPANISH_US
,
283 wxLANGUAGE_SPANISH_VENEZUELA
,
284 wxLANGUAGE_SUNDANESE
,
287 wxLANGUAGE_SWEDISH_FINLAND
,
302 wxLANGUAGE_UKRAINIAN
,
304 wxLANGUAGE_URDU_INDIA
,
305 wxLANGUAGE_URDU_PAKISTAN
,
307 wxLANGUAGE_UZBEK_CYRILLIC
,
308 wxLANGUAGE_UZBEK_LATIN
,
309 wxLANGUAGE_VALENCIAN
,
310 wxLANGUAGE_VIETNAMESE
,
320 /// For custom, user-defined languages.
321 wxLANGUAGE_USER_DEFINED
324 // --- --- --- generated code ends here --- --- ---
326 // ----------------------------------------------------------------------------
327 // wxLanguageInfo: encapsulates wxLanguage to OS native lang.desc.
328 // translation information
329 // ----------------------------------------------------------------------------
331 struct WXDLLIMPEXP_BASE wxLanguageInfo
333 int Language
; // wxLanguage id
334 wxString CanonicalName
; // Canonical name, e.g. fr_FR
336 wxUint32 WinLang
, // Win32 language identifiers
339 wxString Description
; // human-readable name of the language
340 wxLayoutDirection LayoutDirection
;
343 // return the LCID corresponding to this language
344 wxUint32
GetLCID() const;
347 // return the locale name corresponding to this language usable with
348 // setlocale() on the current system
349 wxString
GetLocaleName() const;
352 // for Unix systems GetLocaleName() is trivial so implement it inline here, for
353 // MSW it's implemented in intl.cpp
355 inline wxString
wxLanguageInfo::GetLocaleName() const { return CanonicalName
; }
358 // ----------------------------------------------------------------------------
359 // wxLocaleCategory: the category of locale settings
360 // ----------------------------------------------------------------------------
362 enum wxLocaleCategory
373 // default category for wxLocaleInfo values which only apply to a single
374 // category (e.g. wxLOCALE_SHORT_DATE_FMT)
375 wxLOCALE_CAT_DEFAULT
,
380 // ----------------------------------------------------------------------------
381 // wxLocaleInfo: the items understood by wxLocale::GetInfo()
382 // ----------------------------------------------------------------------------
386 // the thousands separator (for wxLOCALE_CAT_NUMBER or MONEY)
387 wxLOCALE_THOUSANDS_SEP
,
389 // the character used as decimal point (for wxLOCALE_CAT_NUMBER or MONEY)
390 wxLOCALE_DECIMAL_POINT
,
392 // the stftime()-formats used for short/long date and time representations
393 // (under some platforms short and long date formats are the same)
395 // NB: these elements should appear in this order, code in GetInfo() relies
397 wxLOCALE_SHORT_DATE_FMT
,
398 wxLOCALE_LONG_DATE_FMT
,
399 wxLOCALE_DATE_TIME_FMT
,
404 // ----------------------------------------------------------------------------
405 // wxLocale: encapsulates all language dependent settings, including current
406 // message catalogs, date, time and currency formats (TODO) &c
407 // ----------------------------------------------------------------------------
409 enum wxLocaleInitFlags
411 wxLOCALE_DONT_LOAD_DEFAULT
= 0x0000, // don't load wxwin.mo
412 wxLOCALE_LOAD_DEFAULT
= 0x0001 // load wxwin.mo?
413 #if WXWIN_COMPATIBILITY_2_8
414 ,wxLOCALE_CONV_ENCODING
= 0x0002 // no longer used, simply remove
415 // it from the existing code
419 class WXDLLIMPEXP_BASE wxLocale
425 // call Init() if you use this ctor
426 wxLocale() { DoCommonInit(); }
428 // the ctor has a side effect of changing current locale
429 wxLocale(const wxString
& name
, // name (for messages)
430 const wxString
& shortName
= wxEmptyString
, // dir prefix (for msg files)
431 const wxString
& locale
= wxEmptyString
, // locale (for setlocale)
432 bool bLoadDefault
= true // preload wxstd.mo?
433 #if WXWIN_COMPATIBILITY_2_8
434 ,bool bConvertEncoding
= true // convert Win<->Unix if necessary?
440 #if WXWIN_COMPATIBILITY_2_8
441 Init(name
, shortName
, locale
, bLoadDefault
, bConvertEncoding
);
443 Init(name
, shortName
, locale
, bLoadDefault
);
447 wxLocale(int language
, // wxLanguage id or custom language
448 int flags
= wxLOCALE_LOAD_DEFAULT
)
452 Init(language
, flags
);
455 // the same as a function (returns true on success)
456 bool Init(const wxString
& name
,
457 const wxString
& shortName
= wxEmptyString
,
458 const wxString
& locale
= wxEmptyString
,
459 bool bLoadDefault
= true
460 #if WXWIN_COMPATIBILITY_2_8
461 ,bool bConvertEncoding
= true
465 // same as second ctor (returns true on success)
466 bool Init(int language
= wxLANGUAGE_DEFAULT
,
467 int flags
= wxLOCALE_LOAD_DEFAULT
);
469 // restores old locale
472 // Try to get user's (or OS's) preferred language setting.
473 // Return wxLANGUAGE_UNKNOWN if language-guessing algorithm failed
474 static int GetSystemLanguage();
476 // get the encoding used by default for text on this system, returns
477 // wxFONTENCODING_SYSTEM if it couldn't be determined
478 static wxFontEncoding
GetSystemEncoding();
480 // get the string describing the system encoding, return empty string if
481 // couldn't be determined
482 static wxString
GetSystemEncodingName();
484 // get the values of the given locale-dependent datum: the current locale
485 // is used, the US default value is returned if everything else fails
486 static wxString
GetInfo(wxLocaleInfo index
,
487 wxLocaleCategory cat
= wxLOCALE_CAT_DEFAULT
);
489 // return true if the locale was set successfully
490 bool IsOk() const { return m_pszOldLocale
!= NULL
; }
492 // returns locale name
493 const wxString
& GetLocale() const { return m_strLocale
; }
495 // return current locale wxLanguage value
496 int GetLanguage() const { return m_language
; }
498 // return locale name to be passed to setlocale()
499 wxString
GetSysName() const;
501 // return 'canonical' name, i.e. in the form of xx[_YY], where xx is
502 // language code according to ISO 639 and YY is country name
503 // as specified by ISO 3166.
504 wxString
GetCanonicalName() const { return m_strShort
; }
506 // add a prefix to the catalog lookup path: the message catalog files will be
507 // looked up under prefix/<lang>/LC_MESSAGES, prefix/LC_MESSAGES and prefix
510 // This only applies to subsequent invocations of AddCatalog()!
511 static void AddCatalogLookupPathPrefix(const wxString
& prefix
);
513 // add a catalog: it's searched for in standard places (current directory
514 // first, system one after), but the you may prepend additional directories to
515 // the search path with AddCatalogLookupPathPrefix().
517 // The loaded catalog will be used for message lookup by GetString().
519 // Returns 'true' if it was successfully loaded
520 bool AddCatalog(const wxString
& domain
);
521 bool AddCatalog(const wxString
& domain
,
522 wxLanguage msgIdLanguage
, const wxString
& msgIdCharset
);
524 // check if the given locale is provided by OS and C run time
525 static bool IsAvailable(int lang
);
527 // check if the given catalog is loaded
528 bool IsLoaded(const wxString
& domain
) const;
530 // Retrieve the language info struct for the given language
532 // Returns NULL if no info found, pointer must *not* be deleted by caller
533 static const wxLanguageInfo
*GetLanguageInfo(int lang
);
535 // Returns language name in English or empty string if the language
536 // is not in database
537 static wxString
GetLanguageName(int lang
);
539 // Find the language for the given locale string which may be either a
540 // canonical ISO 2 letter language code ("xx"), a language code followed by
541 // the country code ("xx_XX") or a Windows full language name ("Xxxxx...")
543 // Returns NULL if no info found, pointer must *not* be deleted by caller
544 static const wxLanguageInfo
*FindLanguageInfo(const wxString
& locale
);
546 // Add custom language to the list of known languages.
547 // Notes: 1) wxLanguageInfo contains platform-specific data
548 // 2) must be called before Init to have effect
549 static void AddLanguage(const wxLanguageInfo
& info
);
551 // retrieve the translation for a string in all loaded domains unless
552 // the szDomain parameter is specified (and then only this domain is
554 // n - additional parameter for PluralFormsParser
556 // return original string if translation is not available
557 // (in this case an error message is generated the first time
558 // a string is not found; use wxLogNull to suppress it)
560 // domains are searched in the last to first order, i.e. catalogs
561 // added later override those added before.
562 virtual const wxString
& GetString(const wxString
& origString
,
563 const wxString
& domain
= wxEmptyString
) const;
564 // plural form version of the same:
565 virtual const wxString
& GetString(const wxString
& origString
,
566 const wxString
& origString2
,
568 const wxString
& domain
= wxEmptyString
) const;
570 // this is hack to work around a problem with wxGetTranslation() which
571 // returns const wxString& and not wxString, so when it returns untranslated
572 // string, it needs to have a copy of it somewhere
573 static const wxString
& GetUntranslatedString(const wxString
& str
);
575 // Returns the current short name for the locale
576 const wxString
& GetName() const { return m_strShort
; }
578 // return the contents of .po file header
579 wxString
GetHeaderValue(const wxString
& header
,
580 const wxString
& domain
= wxEmptyString
) const;
582 // These two methods are for internal use only. First one creates
583 // ms_languagesDB if it doesn't already exist, second one destroys
585 static void CreateLanguagesDB();
586 static void DestroyLanguagesDB();
589 // find catalog by name in a linked list, return NULL if !found
590 wxMsgCatalog
*FindCatalog(const wxString
& domain
) const;
592 // copy default table of languages from global static array to
593 // m_langugagesInfo, called by InitLanguagesDB
594 static void InitLanguagesDB();
596 // initialize the member fields to default values
599 wxString m_strLocale
, // this locale name
600 m_strShort
; // short name for the locale
601 int m_language
; // this locale wxLanguage value
603 const char *m_pszOldLocale
; // previous locale from setlocale()
604 wxLocale
*m_pOldLocale
; // previous wxLocale
606 wxMsgCatalog
*m_pMsgCat
; // pointer to linked list of catalogs
610 static wxLanguageInfoArray
*ms_languagesDB
;
612 wxDECLARE_NO_COPY_CLASS(wxLocale
);
615 // ----------------------------------------------------------------------------
617 // ----------------------------------------------------------------------------
619 // get the current locale object (note that it may be NULL!)
620 extern WXDLLIMPEXP_BASE wxLocale
* wxGetLocale();
622 // get the translation of the string in the current locale
623 inline const wxString
& wxGetTranslation(const wxString
& str
,
624 const wxString
& domain
= wxEmptyString
)
626 wxLocale
*pLoc
= wxGetLocale();
628 return pLoc
->GetString(str
, domain
);
630 // NB: this function returns reference to a string, so we have to keep
631 // a copy of it somewhere
632 return wxLocale::GetUntranslatedString(str
);
634 inline const wxString
& wxGetTranslation(const wxString
& str1
,
635 const wxString
& str2
,
637 const wxString
& domain
= wxEmptyString
)
639 wxLocale
*pLoc
= wxGetLocale();
641 return pLoc
->GetString(str1
, str2
, n
, domain
);
643 // NB: this function returns reference to a string, so we have to keep
644 // a copy of it somewhere
646 ? wxLocale::GetUntranslatedString(str1
)
647 : wxLocale::GetUntranslatedString(str2
);
652 // the macros should still be defined - otherwise compilation would fail
654 #if !defined(WXINTL_NO_GETTEXT_MACRO)
658 #define wxPLURAL(sing, plur, n) ((n) == 1 ? (sing) : (plur))
661 #define wxTRANSLATE(str) str
663 // NB: we use a template here in order to avoid using
664 // wxLocale::GetUntranslatedString() above, which would be required if
665 // we returned const wxString&; this way, the compiler should be able to
666 // optimize wxGetTranslation() away
668 template<typename TString
>
669 inline TString
wxGetTranslation(TString str
)
672 template<typename TString
, typename TDomain
>
673 inline TString
wxGetTranslation(TString str
, TDomain
WXUNUSED(domain
))
676 template<typename TString
, typename TDomain
>
677 inline TString
wxGetTranslation(TString str1
, TString str2
, size_t n
)
678 { return n
== 1 ? str1
: str2
; }
680 template<typename TString
, typename TDomain
>
681 inline TString
wxGetTranslation(TString str1
, TString str2
, size_t n
,
682 TDomain
WXUNUSED(domain
))
683 { return n
== 1 ? str1
: str2
; }
685 #endif // wxUSE_INTL/!wxUSE_INTL
687 // define this one just in case it occurs somewhere (instead of preferred
689 #if !defined(WXINTL_NO_GETTEXT_MACRO)
690 #if !defined(gettext_noop)
691 #define gettext_noop(str) (str)
698 #endif // _WX_INTL_H_