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 #include "wx/fontenc.h"
26 // ============================================================================
28 // ============================================================================
30 // ----------------------------------------------------------------------------
32 // ----------------------------------------------------------------------------
34 // gettext() style macro (notice that xgettext should be invoked with "-k_"
35 // option to extract the strings inside _() from the sources)
36 #ifndef WXINTL_NO_GETTEXT_MACRO
37 #define _(str) wxGetTranslation(_T(str))
40 // another one which just marks the strings for extraction, but doesn't
41 // perform the translation (use -kwxTRANSLATE with xgettext!)
42 #define wxTRANSLATE(str) _T(str)
44 // ----------------------------------------------------------------------------
46 // ----------------------------------------------------------------------------
48 class WXDLLEXPORT wxLocale
;
49 class WXDLLEXPORT wxMsgCatalog
;
50 class WXDLLEXPORT wxLanguageInfoArray
;
52 // ============================================================================
54 // ============================================================================
56 // ----------------------------------------------------------------------------
57 // wxLanguage: defines all supported languages
58 // ----------------------------------------------------------------------------
60 // --- --- --- generated code begins here --- --- ---
62 // This enum is generated by misc/languages/genlang.py
63 // When making changes, please put them into misc/languages/langtabl.txt
66 // user's default/preffered language as got from OS:
68 // unknown language, if wxLocale::GetSystemLanguage fails:
77 wxLANGUAGE_ARABIC_ALGERIA
,
78 wxLANGUAGE_ARABIC_BAHRAIN
,
79 wxLANGUAGE_ARABIC_EGYPT
,
80 wxLANGUAGE_ARABIC_IRAQ
,
81 wxLANGUAGE_ARABIC_JORDAN
,
82 wxLANGUAGE_ARABIC_KUWAIT
,
83 wxLANGUAGE_ARABIC_LEBANON
,
84 wxLANGUAGE_ARABIC_LIBYA
,
85 wxLANGUAGE_ARABIC_MOROCCO
,
86 wxLANGUAGE_ARABIC_OMAN
,
87 wxLANGUAGE_ARABIC_QATAR
,
88 wxLANGUAGE_ARABIC_SAUDI_ARABIA
,
89 wxLANGUAGE_ARABIC_SUDAN
,
90 wxLANGUAGE_ARABIC_SYRIA
,
91 wxLANGUAGE_ARABIC_TUNISIA
,
92 wxLANGUAGE_ARABIC_UAE
,
93 wxLANGUAGE_ARABIC_YEMEN
,
98 wxLANGUAGE_AZERI_CYRILLIC
,
99 wxLANGUAGE_AZERI_LATIN
,
102 wxLANGUAGE_BELARUSIAN
,
108 wxLANGUAGE_BULGARIAN
,
110 wxLANGUAGE_CAMBODIAN
,
113 wxLANGUAGE_CHINESE_SIMPLIFIED
,
114 wxLANGUAGE_CHINESE_TRADITIONAL
,
115 wxLANGUAGE_CHINESE_HONGKONG
,
116 wxLANGUAGE_CHINESE_MACAU
,
117 wxLANGUAGE_CHINESE_SINGAPORE
,
118 wxLANGUAGE_CHINESE_TAIWAN
,
124 wxLANGUAGE_DUTCH_BELGIAN
,
126 wxLANGUAGE_ENGLISH_UK
,
127 wxLANGUAGE_ENGLISH_US
,
128 wxLANGUAGE_ENGLISH_AUSTRALIA
,
129 wxLANGUAGE_ENGLISH_BELIZE
,
130 wxLANGUAGE_ENGLISH_BOTSWANA
,
131 wxLANGUAGE_ENGLISH_CANADA
,
132 wxLANGUAGE_ENGLISH_CARIBBEAN
,
133 wxLANGUAGE_ENGLISH_DENMARK
,
134 wxLANGUAGE_ENGLISH_EIRE
,
135 wxLANGUAGE_ENGLISH_JAMAICA
,
136 wxLANGUAGE_ENGLISH_NEW_ZEALAND
,
137 wxLANGUAGE_ENGLISH_PHILIPPINES
,
138 wxLANGUAGE_ENGLISH_SOUTH_AFRICA
,
139 wxLANGUAGE_ENGLISH_TRINIDAD
,
140 wxLANGUAGE_ENGLISH_ZIMBABWE
,
141 wxLANGUAGE_ESPERANTO
,
148 wxLANGUAGE_FRENCH_BELGIAN
,
149 wxLANGUAGE_FRENCH_CANADIAN
,
150 wxLANGUAGE_FRENCH_LUXEMBOURG
,
151 wxLANGUAGE_FRENCH_MONACO
,
152 wxLANGUAGE_FRENCH_SWISS
,
157 wxLANGUAGE_GERMAN_AUSTRIAN
,
158 wxLANGUAGE_GERMAN_BELGIUM
,
159 wxLANGUAGE_GERMAN_LIECHTENSTEIN
,
160 wxLANGUAGE_GERMAN_LUXEMBOURG
,
161 wxLANGUAGE_GERMAN_SWISS
,
163 wxLANGUAGE_GREENLANDIC
,
169 wxLANGUAGE_HUNGARIAN
,
170 wxLANGUAGE_ICELANDIC
,
171 wxLANGUAGE_INDONESIAN
,
172 wxLANGUAGE_INTERLINGUA
,
173 wxLANGUAGE_INTERLINGUE
,
174 wxLANGUAGE_INUKTITUT
,
178 wxLANGUAGE_ITALIAN_SWISS
,
183 wxLANGUAGE_KASHMIRI_INDIA
,
186 wxLANGUAGE_KINYARWANDA
,
196 wxLANGUAGE_LITHUANIAN
,
197 wxLANGUAGE_MACEDONIAN
,
200 wxLANGUAGE_MALAYALAM
,
201 wxLANGUAGE_MALAY_BRUNEI_DARUSSALAM
,
202 wxLANGUAGE_MALAY_MALAYSIA
,
207 wxLANGUAGE_MOLDAVIAN
,
208 wxLANGUAGE_MONGOLIAN
,
211 wxLANGUAGE_NEPALI_INDIA
,
212 wxLANGUAGE_NORWEGIAN_BOKMAL
,
213 wxLANGUAGE_NORWEGIAN_NYNORSK
,
219 wxLANGUAGE_PORTUGUESE
,
220 wxLANGUAGE_PORTUGUESE_BRAZILIAN
,
223 wxLANGUAGE_RHAETO_ROMANCE
,
226 wxLANGUAGE_RUSSIAN_UKRAINE
,
230 wxLANGUAGE_SCOTS_GAELIC
,
232 wxLANGUAGE_SERBIAN_CYRILLIC
,
233 wxLANGUAGE_SERBIAN_LATIN
,
234 wxLANGUAGE_SERBO_CROATIAN
,
239 wxLANGUAGE_SINHALESE
,
242 wxLANGUAGE_SLOVENIAN
,
245 wxLANGUAGE_SPANISH_ARGENTINA
,
246 wxLANGUAGE_SPANISH_BOLIVIA
,
247 wxLANGUAGE_SPANISH_CHILE
,
248 wxLANGUAGE_SPANISH_COLOMBIA
,
249 wxLANGUAGE_SPANISH_COSTA_RICA
,
250 wxLANGUAGE_SPANISH_DOMINICAN_REPUBLIC
,
251 wxLANGUAGE_SPANISH_ECUADOR
,
252 wxLANGUAGE_SPANISH_EL_SALVADOR
,
253 wxLANGUAGE_SPANISH_GUATEMALA
,
254 wxLANGUAGE_SPANISH_HONDURAS
,
255 wxLANGUAGE_SPANISH_MEXICAN
,
256 wxLANGUAGE_SPANISH_MODERN
,
257 wxLANGUAGE_SPANISH_NICARAGUA
,
258 wxLANGUAGE_SPANISH_PANAMA
,
259 wxLANGUAGE_SPANISH_PARAGUAY
,
260 wxLANGUAGE_SPANISH_PERU
,
261 wxLANGUAGE_SPANISH_PUERTO_RICO
,
262 wxLANGUAGE_SPANISH_URUGUAY
,
263 wxLANGUAGE_SPANISH_US
,
264 wxLANGUAGE_SPANISH_VENEZUELA
,
265 wxLANGUAGE_SUNDANESE
,
268 wxLANGUAGE_SWEDISH_FINLAND
,
283 wxLANGUAGE_UKRAINIAN
,
285 wxLANGUAGE_URDU_INDIA
,
286 wxLANGUAGE_URDU_PAKISTAN
,
288 wxLANGUAGE_UZBEK_CYRILLIC
,
289 wxLANGUAGE_UZBEK_LATIN
,
290 wxLANGUAGE_VIETNAMESE
,
300 // for custom, user-defined languages:
301 wxLANGUAGE_USER_DEFINED
304 // --- --- --- 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
, // Win32 language identifiers
319 wxString Description
; // human-readable name of the language
322 // ----------------------------------------------------------------------------
323 // wxLocale: encapsulates all language dependent settings, including current
324 // message catalogs, date, time and currency formats (TODO) &c
325 // ----------------------------------------------------------------------------
327 enum wxLocaleInitFlags
329 wxLOCALE_LOAD_DEFAULT
= 0x0001, // load wxwin.mo?
330 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 // get the encoding used by default for text on this system, returns
374 // wxFONTENCODING_SYSTEM if it couldn't be determined
375 static wxFontEncoding
GetSystemEncoding();
377 // get the string describing the system encoding, return empty string if
378 // couldn't be determined
379 static wxString
GetSystemEncodingName();
381 // return TRUE if the locale was set successfully
382 bool IsOk() const { return m_pszOldLocale
!= NULL
; }
384 // returns locale name
385 const wxChar
*GetLocale() const { return m_strLocale
; }
387 // return current locale wxLanguage value
388 int GetLanguage() const { return m_language
; }
390 // return locale name to be passed to setlocale()
391 wxString
GetSysName() const;
393 // return 'canonical' name, i.e. in the form of xx[_YY], where xx is
394 // language code according to ISO 639 and YY is country name
395 // as specified by ISO 3166.
396 wxString
GetCanonicalName() const { return m_strShort
; }
398 // add a prefix to the catalog lookup path: the message catalog files will be
399 // looked up under prefix/<lang>/LC_MESSAGES, prefix/LC_MESSAGES and prefix
402 // This only applies to subsequent invocations of AddCatalog()!
403 static void AddCatalogLookupPathPrefix(const wxString
& prefix
);
405 // add a catalog: it's searched for in standard places (current directory
406 // first, system one after), but the you may prepend additional directories to
407 // the search path with AddCatalogLookupPathPrefix().
409 // The loaded catalog will be used for message lookup by GetString().
411 // Returns 'true' if it was successfully loaded
412 bool AddCatalog(const wxChar
*szDomain
);
414 // check if the given catalog is loaded
415 bool IsLoaded(const wxChar
*szDomain
) const;
417 // Add custom language to the list of known languages.
418 // Notes: 1) wxLanguageInfo contains platform-specific data
419 // 2) must be called before Init to have effect
420 static void AddLanguage(const wxLanguageInfo
& info
);
422 // retrieve the translation for a string in all loaded domains unless
423 // the szDomain parameter is specified (and then only this domain is
426 // return original string if translation is not available
427 // (in this case an error message is generated the first time
428 // a string is not found; use wxLogNull to suppress it)
430 // domains are searched in the last to first order, i.e. catalogs
431 // added later override those added before.
432 const wxMB2WXbuf
GetString(const wxChar
*szOrigString
,
433 const wxChar
*szDomain
= (const wxChar
*) NULL
) const;
435 // Returns the current short name for the locale
436 const wxString
& GetName() const { return m_strShort
; }
438 // These two methods are for internal use only. First one creates
439 // ms_languagesDB if it doesn't already exist, second one destroys
441 static void CreateLanguagesDB();
442 static void DestroyLanguagesDB();
445 // find catalog by name in a linked list, return NULL if !found
446 wxMsgCatalog
*FindCatalog(const wxChar
*szDomain
) const;
448 // copy default table of languages from global static array to
449 // m_langugagesInfo, called by InitLanguagesDB
450 static void InitLanguagesDB();
452 wxString m_strLocale
, // this locale name
453 m_strShort
; // short name for the locale
454 int m_language
; // this locale wxLanguage value
456 const wxChar
*m_pszOldLocale
; // previous locale from setlocale()
457 wxLocale
*m_pOldLocale
; // previous wxLocale
459 wxMsgCatalog
*m_pMsgCat
; // pointer to linked list of catalogs
461 bool m_bConvertEncoding
;
463 static wxLanguageInfoArray
*ms_languagesDB
;
466 // ----------------------------------------------------------------------------
468 // ----------------------------------------------------------------------------
470 // get the current locale object (note that it may be NULL!)
471 extern WXDLLEXPORT wxLocale
* wxGetLocale();
473 // get the translation of the string in the current locale
474 inline const wxMB2WXbuf
wxGetTranslation(const wxChar
*sz
)
476 wxLocale
*pLoc
= wxGetLocale();
478 return pLoc
->GetString(sz
);
480 return (const wxMB2WXbuf
)sz
;
485 // the macros should still be defined - otherwise compilation would fail
487 #if !defined(WXINTL_NO_GETTEXT_MACRO) && !defined(_)
491 #define wxTRANSLATE(str) _T(str)
493 inline const wxChar
*wxGetTranslation(const wxChar
*sz
) { return sz
; }
495 #endif // wxUSE_INTL/!wxUSE_INTL
497 // define this one just in case it occurs somewhere (instead of preferred
499 #if !defined(WXINTL_NO_GETTEXT_MACRO) && !defined(gettext_noop)
500 #define gettext_noop(str) _T(str)
503 #endif // _WX_INTL_H_