1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Internationalization and localisation for wxWindows
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
16 #pragma interface "intl.h"
20 #include "wx/string.h"
24 // ============================================================================
26 // ============================================================================
28 // ----------------------------------------------------------------------------
30 // ----------------------------------------------------------------------------
32 // gettext() style macro (notice that xgettext should be invoked with "-k_"
33 // option to extract the strings inside _() from the sources)
34 #ifndef WXINTL_NO_GETTEXT_MACRO
35 #define _(str) wxGetTranslation(_T(str))
38 // another one which just marks the strings for extraction, but doesn't
39 // perform the translation (use -kwxTRANSLATE with xgettext!)
40 #define wxTRANSLATE(str) _T(str)
42 // ----------------------------------------------------------------------------
44 // ----------------------------------------------------------------------------
46 class WXDLLEXPORT wxLocale
;
47 class WXDLLEXPORT wxMsgCatalog
;
48 class WXDLLEXPORT wxLanguageInfoArray
;
50 // ============================================================================
52 // ============================================================================
54 // ----------------------------------------------------------------------------
55 // wxLanguage: defines all supported languages
56 // ----------------------------------------------------------------------------
58 // --- --- --- generated code begins here --- --- ---
60 // This enum is generated by misc/languages/genlang.py
61 // When making changes, please put them into misc/languages/langtabl.txt
64 // user's default/preffered language as got from OS:
66 // unknown language, if wxLocale::GetSystemLanguage fails:
75 wxLANGUAGE_ARABIC_ALGERIA
,
76 wxLANGUAGE_ARABIC_BAHRAIN
,
77 wxLANGUAGE_ARABIC_EGYPT
,
78 wxLANGUAGE_ARABIC_IRAQ
,
79 wxLANGUAGE_ARABIC_JORDAN
,
80 wxLANGUAGE_ARABIC_KUWAIT
,
81 wxLANGUAGE_ARABIC_LEBANON
,
82 wxLANGUAGE_ARABIC_LIBYA
,
83 wxLANGUAGE_ARABIC_MOROCCO
,
84 wxLANGUAGE_ARABIC_OMAN
,
85 wxLANGUAGE_ARABIC_QATAR
,
86 wxLANGUAGE_ARABIC_SAUDI_ARABIA
,
87 wxLANGUAGE_ARABIC_SUDAN
,
88 wxLANGUAGE_ARABIC_SYRIA
,
89 wxLANGUAGE_ARABIC_TUNISIA
,
90 wxLANGUAGE_ARABIC_UAE
,
91 wxLANGUAGE_ARABIC_YEMEN
,
96 wxLANGUAGE_AZERI_CYRILLIC
,
97 wxLANGUAGE_AZERI_LATIN
,
100 wxLANGUAGE_BELARUSIAN
,
106 wxLANGUAGE_BULGARIAN
,
108 wxLANGUAGE_CAMBODIAN
,
111 wxLANGUAGE_CHINESE_SIMPLIFIED
,
112 wxLANGUAGE_CHINESE_TRADITIONAL
,
113 wxLANGUAGE_CHINESE_HONGKONG
,
114 wxLANGUAGE_CHINESE_MACAU
,
115 wxLANGUAGE_CHINESE_SINGAPORE
,
116 wxLANGUAGE_CHINESE_TAIWAN
,
122 wxLANGUAGE_DUTCH_BELGIAN
,
124 wxLANGUAGE_ENGLISH_UK
,
125 wxLANGUAGE_ENGLISH_US
,
126 wxLANGUAGE_ENGLISH_AUSTRALIA
,
127 wxLANGUAGE_ENGLISH_BELIZE
,
128 wxLANGUAGE_ENGLISH_BOTSWANA
,
129 wxLANGUAGE_ENGLISH_CANADA
,
130 wxLANGUAGE_ENGLISH_CARIBBEAN
,
131 wxLANGUAGE_ENGLISH_DENMARK
,
132 wxLANGUAGE_ENGLISH_EIRE
,
133 wxLANGUAGE_ENGLISH_JAMAICA
,
134 wxLANGUAGE_ENGLISH_NEW_ZEALAND
,
135 wxLANGUAGE_ENGLISH_PHILIPPINES
,
136 wxLANGUAGE_ENGLISH_SOUTH_AFRICA
,
137 wxLANGUAGE_ENGLISH_TRINIDAD
,
138 wxLANGUAGE_ENGLISH_ZIMBABWE
,
139 wxLANGUAGE_ESPERANTO
,
146 wxLANGUAGE_FRENCH_BELGIAN
,
147 wxLANGUAGE_FRENCH_CANADIAN
,
148 wxLANGUAGE_FRENCH_LUXEMBOURG
,
149 wxLANGUAGE_FRENCH_MONACO
,
150 wxLANGUAGE_FRENCH_SWISS
,
155 wxLANGUAGE_GERMAN_AUSTRIAN
,
156 wxLANGUAGE_GERMAN_BELGIUM
,
157 wxLANGUAGE_GERMAN_LIECHTENSTEIN
,
158 wxLANGUAGE_GERMAN_LUXEMBOURG
,
159 wxLANGUAGE_GERMAN_SWISS
,
161 wxLANGUAGE_GREENLANDIC
,
167 wxLANGUAGE_HUNGARIAN
,
168 wxLANGUAGE_ICELANDIC
,
169 wxLANGUAGE_INDONESIAN
,
170 wxLANGUAGE_INTERLINGUA
,
171 wxLANGUAGE_INTERLINGUE
,
172 wxLANGUAGE_INUKTITUT
,
176 wxLANGUAGE_ITALIAN_SWISS
,
181 wxLANGUAGE_KASHMIRI_INDIA
,
184 wxLANGUAGE_KINYARWANDA
,
194 wxLANGUAGE_LITHUANIAN
,
195 wxLANGUAGE_MACEDONIAN
,
198 wxLANGUAGE_MALAYALAM
,
199 wxLANGUAGE_MALAY_BRUNEI_DARUSSALAM
,
200 wxLANGUAGE_MALAY_MALAYSIA
,
205 wxLANGUAGE_MOLDAVIAN
,
206 wxLANGUAGE_MONGOLIAN
,
209 wxLANGUAGE_NEPALI_INDIA
,
210 wxLANGUAGE_NORWEGIAN_BOKMAL
,
211 wxLANGUAGE_NORWEGIAN_NYNORSK
,
217 wxLANGUAGE_PORTUGUESE
,
218 wxLANGUAGE_PORTUGUESE_BRAZILIAN
,
221 wxLANGUAGE_RHAETO_ROMANCE
,
224 wxLANGUAGE_RUSSIAN_UKRAINE
,
228 wxLANGUAGE_SCOTS_GAELIC
,
230 wxLANGUAGE_SERBIAN_CYRILLIC
,
231 wxLANGUAGE_SERBIAN_LATIN
,
232 wxLANGUAGE_SERBO_CROATIAN
,
237 wxLANGUAGE_SINHALESE
,
240 wxLANGUAGE_SLOVENIAN
,
243 wxLANGUAGE_SPANISH_ARGENTINA
,
244 wxLANGUAGE_SPANISH_BOLIVIA
,
245 wxLANGUAGE_SPANISH_CHILE
,
246 wxLANGUAGE_SPANISH_COLOMBIA
,
247 wxLANGUAGE_SPANISH_COSTA_RICA
,
248 wxLANGUAGE_SPANISH_DOMINICAN_REPUBLIC
,
249 wxLANGUAGE_SPANISH_ECUADOR
,
250 wxLANGUAGE_SPANISH_EL_SALVADOR
,
251 wxLANGUAGE_SPANISH_GUATEMALA
,
252 wxLANGUAGE_SPANISH_HONDURAS
,
253 wxLANGUAGE_SPANISH_MEXICAN
,
254 wxLANGUAGE_SPANISH_MODERN
,
255 wxLANGUAGE_SPANISH_NICARAGUA
,
256 wxLANGUAGE_SPANISH_PANAMA
,
257 wxLANGUAGE_SPANISH_PARAGUAY
,
258 wxLANGUAGE_SPANISH_PERU
,
259 wxLANGUAGE_SPANISH_PUERTO_RICO
,
260 wxLANGUAGE_SPANISH_URUGUAY
,
261 wxLANGUAGE_SPANISH_US
,
262 wxLANGUAGE_SPANISH_VENEZUELA
,
263 wxLANGUAGE_SUNDANESE
,
266 wxLANGUAGE_SWEDISH_FINLAND
,
281 wxLANGUAGE_UKRAINIAN
,
283 wxLANGUAGE_URDU_INDIA
,
284 wxLANGUAGE_URDU_PAKISTAN
,
286 wxLANGUAGE_UZBEK_CYRILLIC
,
287 wxLANGUAGE_UZBEK_LATIN
,
288 wxLANGUAGE_VIETNAMESE
,
298 // for custom, user-defined languages:
299 wxLANGUAGE_USER_DEFINED
302 // --- --- --- generated code ends here --- --- ---
306 // ----------------------------------------------------------------------------
307 // wxLanguageInfo: encapsulates wxLanguage to OS native lang.desc.
308 // translation information
309 // ----------------------------------------------------------------------------
311 struct WXDLLEXPORT wxLanguageInfo
313 int Language
; // wxLanguage id
314 wxString CanonicalName
; // Canonical name, e.g. fr_FR
316 wxUint32 WinLang
, WinSublang
; // Win32 language identifiers
318 wxString Description
; // human-readable name of the language
321 // ----------------------------------------------------------------------------
322 // wxLocale: encapsulates all language dependent settings, including current
323 // message catalogs, date, time and currency formats (TODO) &c
324 // ----------------------------------------------------------------------------
326 enum wxLocaleInitFlags
328 wxLOCALE_LOAD_DEFAULT
= 0x0001, // load wxwin.mo?
329 wxLOCALE_CONV_ENCODING
= 0x0002 // convert encoding on the fly?
333 class WXDLLEXPORT wxLocale
339 // call Init() if you use this ctor
341 // the ctor has a side effect of changing current locale
342 wxLocale(const wxChar
*szName
, // name (for messages)
343 const wxChar
*szShort
= (const wxChar
*) NULL
, // dir prefix (for msg files)
344 const wxChar
*szLocale
= (const wxChar
*) NULL
, // locale (for setlocale)
345 bool bLoadDefault
= TRUE
, // preload wxstd.mo?
346 bool bConvertEncoding
= FALSE
) // convert Win<->Unix if neccessary?
348 Init(szName
, szShort
, szLocale
, bLoadDefault
, bConvertEncoding
);
351 wxLocale(int language
, // wxLanguage id or custom language
352 int flags
= wxLOCALE_LOAD_DEFAULT
| wxLOCALE_CONV_ENCODING
)
353 { Init(language
, flags
); }
355 // the same as a function (returns TRUE on success)
356 bool Init(const wxChar
*szName
,
357 const wxChar
*szShort
= (const wxChar
*) NULL
,
358 const wxChar
*szLocale
= (const wxChar
*) NULL
,
359 bool bLoadDefault
= TRUE
,
360 bool bConvertEncoding
= FALSE
);
362 // same as second ctor (returns TRUE on success)
363 bool Init(int language
= wxLANGUAGE_DEFAULT
,
364 int flags
= wxLOCALE_LOAD_DEFAULT
| wxLOCALE_CONV_ENCODING
);
366 // restores old locale
369 // Try to get user's (or OS's) prefered language setting.
370 // Return wxLANGUAGE_UNKNOWN if language-guessing algorithm failed
371 static int GetSystemLanguage();
373 // return TRUE if the locale was set successfully
374 bool IsOk() const { return m_pszOldLocale
!= NULL
; }
376 // returns locale name
377 const wxChar
*GetLocale() const { return m_strLocale
; }
379 // return current locale wxLanguage value
380 int GetLanguage() const { return m_language
; }
382 // return locale name to be passed to setlocale()
383 wxString
GetSysName() const;
385 // return 'canonical' name, i.e. in the form of xx[_YY], where xx is
386 // language code according to ISO 639 and YY is country name
387 // as specified by ISO 3166.
388 wxString
GetCanonicalName() const { return m_strShort
; }
390 // add a prefix to the catalog lookup path: the message catalog files will be
391 // looked up under prefix/<lang>/LC_MESSAGES, prefix/LC_MESSAGES and prefix
394 // This only applies to subsequent invocations of AddCatalog()!
395 static void AddCatalogLookupPathPrefix(const wxString
& prefix
);
397 // add a catalog: it's searched for in standard places (current directory
398 // first, system one after), but the you may prepend additional directories to
399 // the search path with AddCatalogLookupPathPrefix().
401 // The loaded catalog will be used for message lookup by GetString().
403 // Returns 'true' if it was successfully loaded
404 bool AddCatalog(const wxChar
*szDomain
);
406 // check if the given catalog is loaded
407 bool IsLoaded(const wxChar
*szDomain
) const;
409 // Add custom language to the list of known languages.
410 // Notes: 1) wxLanguageInfo contains platform-specific data
411 // 2) must be called before Init to have effect
412 static void AddLanguage(const wxLanguageInfo
& info
);
414 // retrieve the translation for a string in all loaded domains unless
415 // the szDomain parameter is specified (and then only this domain is
418 // return original string if translation is not available
419 // (in this case an error message is generated the first time
420 // a string is not found; use wxLogNull to suppress it)
422 // domains are searched in the last to first order, i.e. catalogs
423 // added later override those added before.
424 const wxMB2WXbuf
GetString(const wxChar
*szOrigString
,
425 const wxChar
*szDomain
= (const wxChar
*) NULL
) const;
427 // Returns the current short name for the locale
428 const wxString
& GetName() const { return m_strShort
; }
430 // These two methods are for internal use only. First one creates
431 // ms_languagesDB if it doesn't already exist, second one destroys
433 static void CreateLanguagesDB();
434 static void DestroyLanguagesDB();
437 // find catalog by name in a linked list, return NULL if !found
438 wxMsgCatalog
*FindCatalog(const wxChar
*szDomain
) const;
440 // copy default table of languages from global static array to
441 // m_langugagesInfo, called by InitLanguagesDB
442 static void InitLanguagesDB();
444 wxString m_strLocale
, // this locale name
445 m_strShort
; // short name for the locale
446 int m_language
; // this locale wxLanguage value
448 const wxChar
*m_pszOldLocale
; // previous locale from setlocale()
449 wxLocale
*m_pOldLocale
; // previous wxLocale
451 wxMsgCatalog
*m_pMsgCat
; // pointer to linked list of catalogs
453 bool m_bConvertEncoding
;
455 static wxLanguageInfoArray
*ms_languagesDB
;
458 // ----------------------------------------------------------------------------
460 // ----------------------------------------------------------------------------
462 // get the current locale object (note that it may be NULL!)
463 extern WXDLLEXPORT wxLocale
* wxGetLocale();
465 // get the translation of the string in the current locale
466 inline const wxMB2WXbuf
wxGetTranslation(const wxChar
*sz
)
468 wxLocale
*pLoc
= wxGetLocale();
470 return pLoc
->GetString(sz
);
472 return (const wxMB2WXbuf
)sz
;
477 // the macros should still be defined - otherwise compilation would fail
479 #if !defined(WXINTL_NO_GETTEXT_MACRO) && !defined(_)
483 #define wxTRANSLATE(str) _T(str)
485 inline const wxChar
*wxGetTranslation(const wxChar
*sz
) { return sz
; }
487 #endif // wxUSE_INTL/!wxUSE_INTL
489 // define this one just in case it occurs somewhere (instead of preferred
491 #if !defined(WXINTL_NO_GETTEXT_MACRO) && !defined(gettext_noop)
492 #define gettext_noop(str) _T(str)