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 // ----------------------------------------------------------------------------
59 // This enum is generated by misc/languages/genlang.py
60 // When making changes, please put them into misc/languages/langtabl.txt
63 // 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 // ----------------------------------------------------------------------------
303 // wxLanguageInfo: encapsulates wxLanguage to OS native lang.desc.
304 // translation information
305 // ----------------------------------------------------------------------------
307 struct WXDLLEXPORT wxLanguageInfo
309 int Language
; // wxLanguage id
310 wxString CanonicalName
; // Canonical name, e.g. fr_FR
312 wxUint32 WinLang
, WinSublang
; // Win32 language identifiers
314 wxString Description
; // human-readable name of the language
317 // ----------------------------------------------------------------------------
318 // wxLocale: encapsulates all language dependent settings, including current
319 // message catalogs, date, time and currency formats (TODO) &c
320 // ----------------------------------------------------------------------------
322 enum wxLocaleInitFlags
324 wxLOCALE_LOAD_DEFAULT
= 0x0001, // load wxwin.mo?
325 wxLOCALE_CONV_ENCODING
= 0x0002 // convert encoding on the fly?
329 class WXDLLEXPORT wxLocale
335 // call Init() if you use this ctor
337 // the ctor has a side effect of changing current locale
338 wxLocale(const wxChar
*szName
, // name (for messages)
339 const wxChar
*szShort
= (const wxChar
*) NULL
, // dir prefix (for msg files)
340 const wxChar
*szLocale
= (const wxChar
*) NULL
, // locale (for setlocale)
341 bool bLoadDefault
= TRUE
, // preload wxstd.mo?
342 bool bConvertEncoding
= FALSE
) // convert Win<->Unix if neccessary?
344 m_languagesDB
= NULL
;
345 Init(szName
, szShort
, szLocale
, bLoadDefault
, bConvertEncoding
);
348 wxLocale(int language
, // wxLanguage id or custom language
349 int flags
= wxLOCALE_LOAD_DEFAULT
| wxLOCALE_CONV_ENCODING
)
350 { Init(language
, flags
); }
352 // the same as a function (returns TRUE on success)
353 bool Init(const wxChar
*szName
,
354 const wxChar
*szShort
= (const wxChar
*) NULL
,
355 const wxChar
*szLocale
= (const wxChar
*) NULL
,
356 bool bLoadDefault
= TRUE
,
357 bool bConvertEncoding
= FALSE
);
359 // same as second ctor (returns TRUE on success)
360 bool Init(int language
= wxLANGUAGE_DEFAULT
,
361 int flags
= wxLOCALE_LOAD_DEFAULT
| wxLOCALE_CONV_ENCODING
);
363 // restores old locale
366 // Try to get user's (or OS's) prefered language setting.
367 // Return wxLANGUAGE_UNKNOWN if language-guessing algorithm failed
368 int GetSystemLanguage() const;
370 // return TRUE if the locale was set successfully
371 bool IsOk() const { return m_pszOldLocale
!= NULL
; }
373 // returns locale name
374 const wxChar
*GetLocale() const { return m_strLocale
; }
376 // return current locale wxLanguage value
377 int GetLanguage() const { return m_language
; }
379 // return locale name to be passed to setlocale()
380 wxString
GetSysName() const;
382 // return 'canonical' name, i.e. in the form of xx[_YY], where xx is
383 // language code according to ISO 639 and YY is country name
384 // as specified by ISO 3166.
385 wxString
GetCanonicalName() const { return m_strShort
; }
387 // add a prefix to the catalog lookup path: the message catalog files will be
388 // looked up under prefix/<lang>/LC_MESSAGES, prefix/LC_MESSAGES and prefix
391 // This only applies to subsequent invocations of AddCatalog()!
392 static void AddCatalogLookupPathPrefix(const wxString
& prefix
);
394 // add a catalog: it's searched for in standard places (current directory
395 // first, system one after), but the you may prepend additional directories to
396 // the search path with AddCatalogLookupPathPrefix().
398 // The loaded catalog will be used for message lookup by GetString().
400 // Returns 'true' if it was successfully loaded
401 bool AddCatalog(const wxChar
*szDomain
);
403 // check if the given catalog is loaded
404 bool IsLoaded(const wxChar
*szDomain
) const;
406 // Add custom language to the list of known languages.
407 // Notes: 1) wxLanguageInfo contains platform-specific data
408 // 2) must be called before Init to have effect
409 void AddLanguage(const wxLanguageInfo
& info
);
411 // retrieve the translation for a string in all loaded domains unless
412 // the szDomain parameter is specified (and then only this domain is
415 // return original string if translation is not available
416 // (in this case an error message is generated the first time
417 // a string is not found; use wxLogNull to suppress it)
419 // domains are searched in the last to first order, i.e. catalogs
420 // added later override those added before.
421 const wxMB2WXbuf
GetString(const wxChar
*szOrigString
,
422 const wxChar
*szDomain
= (const wxChar
*) NULL
) const;
424 // Returns the current short name for the locale
425 const wxString
& GetName() const { return m_strShort
; }
428 // find catalog by name in a linked list, return NULL if !found
429 wxMsgCatalog
*FindCatalog(const wxChar
*szDomain
) const;
431 // copy default table of languages from global static array to
433 void InitLanguagesDB();
435 wxString m_strLocale
, // this locale name
436 m_strShort
; // short name for the locale
437 int m_language
; // this locale wxLanguage value
439 const wxChar
*m_pszOldLocale
; // previous locale from setlocale()
440 wxLocale
*m_pOldLocale
; // previous wxLocale
442 wxMsgCatalog
*m_pMsgCat
; // pointer to linked list of catalogs
444 bool m_bConvertEncoding
;
446 wxLanguageInfoArray
*m_languagesDB
;
449 // ----------------------------------------------------------------------------
451 // ----------------------------------------------------------------------------
453 // get the current locale object (note that it may be NULL!)
454 extern WXDLLEXPORT wxLocale
* wxGetLocale();
456 // get the translation of the string in the current locale
457 inline const wxMB2WXbuf
wxGetTranslation(const wxChar
*sz
)
459 wxLocale
*pLoc
= wxGetLocale();
461 return pLoc
->GetString(sz
);
463 return (const wxMB2WXbuf
)sz
;
468 // the macros should still be defined - otherwise compilation would fail
470 #if !defined(WXINTL_NO_GETTEXT_MACRO) && !defined(_)
474 #define wxTRANSLATE(str) _T(str)
476 inline const wxChar
*wxGetTranslation(const wxChar
*sz
) { return sz
; }
478 #endif // wxUSE_INTL/!wxUSE_INTL
480 // define this one just in case it occurs somewhere (instead of preferred
482 #if !defined(WXINTL_NO_GETTEXT_MACRO) && !defined(gettext_noop)
483 #define gettext_noop(str) _T(str)