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 // ----------------------------------------------------------------------------
45 class WXDLLEXPORT wxLocale
;
46 class WXDLLEXPORT wxMsgCatalog
;
47 class WXDLLEXPORT wxLanguageInfoArray
;
49 // ============================================================================
51 // ============================================================================
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:
65 // unknown language, if wxLocale::GetSystemLanguage fails:
74 wxLANGUAGE_ARABIC_ALGERIA
,
75 wxLANGUAGE_ARABIC_BAHRAIN
,
76 wxLANGUAGE_ARABIC_EGYPT
,
77 wxLANGUAGE_ARABIC_IRAQ
,
78 wxLANGUAGE_ARABIC_JORDAN
,
79 wxLANGUAGE_ARABIC_KUWAIT
,
80 wxLANGUAGE_ARABIC_LEBANON
,
81 wxLANGUAGE_ARABIC_LIBYA
,
82 wxLANGUAGE_ARABIC_MOROCCO
,
83 wxLANGUAGE_ARABIC_OMAN
,
84 wxLANGUAGE_ARABIC_QATAR
,
85 wxLANGUAGE_ARABIC_SAUDI_ARABIA
,
86 wxLANGUAGE_ARABIC_SUDAN
,
87 wxLANGUAGE_ARABIC_SYRIA
,
88 wxLANGUAGE_ARABIC_TUNISIA
,
89 wxLANGUAGE_ARABIC_UAE
,
90 wxLANGUAGE_ARABIC_YEMEN
,
95 wxLANGUAGE_AZERI_CYRILLIC
,
96 wxLANGUAGE_AZERI_LATIN
,
99 wxLANGUAGE_BELARUSIAN
,
105 wxLANGUAGE_BULGARIAN
,
107 wxLANGUAGE_CAMBODIAN
,
110 wxLANGUAGE_CHINESE_SIMPLIFIED
,
111 wxLANGUAGE_CHINESE_TRADITIONAL
,
112 wxLANGUAGE_CHINESE_HONGKONG
,
113 wxLANGUAGE_CHINESE_MACAU
,
114 wxLANGUAGE_CHINESE_SINGAPORE
,
115 wxLANGUAGE_CHINESE_TAIWAN
,
121 wxLANGUAGE_DUTCH_BELGIAN
,
123 wxLANGUAGE_ENGLISH_UK
,
124 wxLANGUAGE_ENGLISH_US
,
125 wxLANGUAGE_ENGLISH_AUSTRALIA
,
126 wxLANGUAGE_ENGLISH_BELIZE
,
127 wxLANGUAGE_ENGLISH_BOTSWANA
,
128 wxLANGUAGE_ENGLISH_CANADA
,
129 wxLANGUAGE_ENGLISH_CARIBBEAN
,
130 wxLANGUAGE_ENGLISH_DENMARK
,
131 wxLANGUAGE_ENGLISH_EIRE
,
132 wxLANGUAGE_ENGLISH_JAMAICA
,
133 wxLANGUAGE_ENGLISH_NEW_ZEALAND
,
134 wxLANGUAGE_ENGLISH_PHILIPPINES
,
135 wxLANGUAGE_ENGLISH_SOUTH_AFRICA
,
136 wxLANGUAGE_ENGLISH_TRINIDAD
,
137 wxLANGUAGE_ENGLISH_ZIMBABWE
,
138 wxLANGUAGE_ESPERANTO
,
145 wxLANGUAGE_FRENCH_BELGIAN
,
146 wxLANGUAGE_FRENCH_CANADIAN
,
147 wxLANGUAGE_FRENCH_LUXEMBOURG
,
148 wxLANGUAGE_FRENCH_MONACO
,
149 wxLANGUAGE_FRENCH_SWISS
,
154 wxLANGUAGE_GERMAN_AUSTRIAN
,
155 wxLANGUAGE_GERMAN_BELGIUM
,
156 wxLANGUAGE_GERMAN_LIECHTENSTEIN
,
157 wxLANGUAGE_GERMAN_LUXEMBOURG
,
158 wxLANGUAGE_GERMAN_SWISS
,
160 wxLANGUAGE_GREENLANDIC
,
166 wxLANGUAGE_HUNGARIAN
,
167 wxLANGUAGE_ICELANDIC
,
168 wxLANGUAGE_INDONESIAN
,
169 wxLANGUAGE_INTERLINGUA
,
170 wxLANGUAGE_INTERLINGUE
,
171 wxLANGUAGE_INUKTITUT
,
175 wxLANGUAGE_ITALIAN_SWISS
,
180 wxLANGUAGE_KASHMIRI_INDIA
,
183 wxLANGUAGE_KINYARWANDA
,
193 wxLANGUAGE_LITHUANIAN
,
194 wxLANGUAGE_MACEDONIAN
,
197 wxLANGUAGE_MALAYALAM
,
198 wxLANGUAGE_MALAY_BRUNEI_DARUSSALAM
,
199 wxLANGUAGE_MALAY_MALAYSIA
,
204 wxLANGUAGE_MOLDAVIAN
,
205 wxLANGUAGE_MONGOLIAN
,
208 wxLANGUAGE_NEPALI_INDIA
,
209 wxLANGUAGE_NORWEGIAN_BOKMAL
,
210 wxLANGUAGE_NORWEGIAN_NYNORSK
,
216 wxLANGUAGE_PORTUGUESE
,
217 wxLANGUAGE_PORTUGUESE_BRAZILIAN
,
220 wxLANGUAGE_RHAETO_ROMANCE
,
223 wxLANGUAGE_RUSSIAN_UKRAINE
,
227 wxLANGUAGE_SCOTS_GAELIC
,
229 wxLANGUAGE_SERBIAN_CYRILLIC
,
230 wxLANGUAGE_SERBIAN_LATIN
,
231 wxLANGUAGE_SERBO_CROATIAN
,
236 wxLANGUAGE_SINHALESE
,
239 wxLANGUAGE_SLOVENIAN
,
242 wxLANGUAGE_SPANISH_ARGENTINA
,
243 wxLANGUAGE_SPANISH_BOLIVIA
,
244 wxLANGUAGE_SPANISH_CHILE
,
245 wxLANGUAGE_SPANISH_COLOMBIA
,
246 wxLANGUAGE_SPANISH_COSTA_RICA
,
247 wxLANGUAGE_SPANISH_DOMINICAN_REPUBLIC
,
248 wxLANGUAGE_SPANISH_ECUADOR
,
249 wxLANGUAGE_SPANISH_EL_SALVADOR
,
250 wxLANGUAGE_SPANISH_GUATEMALA
,
251 wxLANGUAGE_SPANISH_HONDURAS
,
252 wxLANGUAGE_SPANISH_MEXICAN
,
253 wxLANGUAGE_SPANISH_MODERN
,
254 wxLANGUAGE_SPANISH_NICARAGUA
,
255 wxLANGUAGE_SPANISH_PANAMA
,
256 wxLANGUAGE_SPANISH_PARAGUAY
,
257 wxLANGUAGE_SPANISH_PERU
,
258 wxLANGUAGE_SPANISH_PUERTO_RICO
,
259 wxLANGUAGE_SPANISH_URUGUAY
,
260 wxLANGUAGE_SPANISH_US
,
261 wxLANGUAGE_SPANISH_VENEZUELA
,
262 wxLANGUAGE_SUNDANESE
,
265 wxLANGUAGE_SWEDISH_FINLAND
,
280 wxLANGUAGE_UKRAINIAN
,
282 wxLANGUAGE_URDU_INDIA
,
283 wxLANGUAGE_URDU_PAKISTAN
,
285 wxLANGUAGE_UZBEK_CYRILLIC
,
286 wxLANGUAGE_UZBEK_LATIN
,
287 wxLANGUAGE_VIETNAMESE
,
297 // for custom, user-defined languages:
298 wxLANGUAGE_USER_DEFINED
301 // ----------------------------------------------------------------------------
302 // wxLanguageInfo: encapsulates wxLanguage to OS native lang.desc.
303 // translation information
304 // ----------------------------------------------------------------------------
306 struct WXDLLEXPORT wxLanguageInfo
308 int Language
; // wxLanguage id
309 wxString CanonicalName
; // Canonical name, e.g. fr_FR
311 wxUint32 WinLang
, WinSublang
; // Win32 language identifiers
313 wxString Description
; // human-readable name of the language
319 // ----------------------------------------------------------------------------
320 // wxLocale: encapsulates all language dependent settings, including current
321 // message catalogs, date, time and currency formats (TODO) &c
322 // ----------------------------------------------------------------------------
324 enum wxLocaleInitFlags
326 wxLOCALE_LOAD_DEFAULT
= 0x0001, // load wxwin.mo?
327 wxLOCALE_CONV_ENCODING
= 0x0002 // convert encoding on the fly?
331 class WXDLLEXPORT wxLocale
337 // call Init() if you use this ctor
339 // the ctor has a side effect of changing current locale
340 wxLocale(const wxChar
*szName
, // name (for messages)
341 const wxChar
*szShort
= (const wxChar
*) NULL
, // dir prefix (for msg files)
342 const wxChar
*szLocale
= (const wxChar
*) NULL
, // locale (for setlocale)
343 bool bLoadDefault
= TRUE
, // preload wxstd.mo?
344 bool bConvertEncoding
= FALSE
) // convert Win<->Unix if neccessary?
346 m_languagesDB
= NULL
;
347 Init(szName
, szShort
, szLocale
, bLoadDefault
, bConvertEncoding
);
350 wxLocale(int language
, // wxLanguage identifier
351 int flags
= wxLOCALE_LOAD_DEFAULT
| wxLOCALE_CONV_ENCODING
)
352 { Init(language
, flags
); }
354 // the same as a function (returns TRUE on success)
355 bool Init(const wxChar
*szName
,
356 const wxChar
*szShort
= (const wxChar
*) NULL
,
357 const wxChar
*szLocale
= (const wxChar
*) NULL
,
358 bool bLoadDefault
= TRUE
,
359 bool bConvertEncoding
= FALSE
);
361 bool Init(int language
= wxLANGUAGE_DEFAULT
,
362 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 value or wxLANGUAGE_UNKNOWN if language-guessing
369 int GetSystemLanguage() const;
371 // return TRUE if the locale was set successfully
372 bool IsOk() const { return m_pszOldLocale
!= NULL
; }
374 // returns locale name
375 const wxChar
*GetLocale() const { return m_strLocale
; }
377 // return current locale wxLanguage value
378 int GetLanguage() const { return m_language
; }
380 // return locale name to be passed to setlocale()
381 wxString
GetSysName() const;
383 // return 'canonical' name, i.e. in the form of xx[_YY], where xx is
384 // language code according to ISO 639 and YY is country name
385 // as specified by ISO 3166.
386 wxString
GetCanonicalName() const { return m_strShort
; }
388 // add a prefix to the catalog lookup path: the message catalog files will be
389 // looked up under prefix/<lang>/LC_MESSAGES, prefix/LC_MESSAGES and prefix
392 // This only applies to subsequent invocations of AddCatalog()!
393 static void AddCatalogLookupPathPrefix(const wxString
& prefix
);
395 // add a catalog: it's searched for in standard places (current directory
396 // first, system one after), but the you may prepend additional directories to
397 // the search path with AddCatalogLookupPathPrefix().
399 // The loaded catalog will be used for message lookup by GetString().
401 // Returns 'true' if it was successfully loaded
402 bool AddCatalog(const wxChar
*szDomain
);
404 // check if the given catalog is loaded
405 bool IsLoaded(const wxChar
*szDomain
) const;
407 // Add custom language to the list of known languages.
408 // Notes: 1) wxLanguageInfo contains platform-specific data
409 // 2) must be called before Init to have effect
410 void AddLanguage(const wxLanguageInfo
& info
);
412 // retrieve the translation for a string in all loaded domains unless
413 // the szDomain parameter is specified (and then only this domain is
416 // return original string if translation is not available
417 // (in this case an error message is generated the first time
418 // a string is not found; use wxLogNull to suppress it)
420 // domains are searched in the last to first order, i.e. catalogs
421 // added later override those added before.
422 const wxMB2WXbuf
GetString(const wxChar
*szOrigString
,
423 const wxChar
*szDomain
= (const wxChar
*) NULL
) const;
425 // Returns the current short name for the locale
426 const wxString
& GetName() const { return m_strShort
; }
429 // find catalog by name in a linked list, return NULL if !found
430 wxMsgCatalog
*FindCatalog(const wxChar
*szDomain
) const;
432 // copy default table of languages from global static array to
434 void InitLanguagesDB();
436 wxString m_strLocale
, // this locale name
437 m_strShort
; // short name for the locale
438 int m_language
; // this locale wxLanguage value
440 const wxChar
*m_pszOldLocale
; // previous locale from setlocale()
441 wxLocale
*m_pOldLocale
; // previous wxLocale
443 wxMsgCatalog
*m_pMsgCat
; // pointer to linked list of catalogs
445 bool m_bConvertEncoding
;
447 wxLanguageInfoArray
*m_languagesDB
;
450 // ----------------------------------------------------------------------------
452 // ----------------------------------------------------------------------------
454 // get the current locale object (note that it may be NULL!)
455 extern WXDLLEXPORT wxLocale
* wxGetLocale();
457 // get the translation of the string in the current locale
458 inline const wxMB2WXbuf
wxGetTranslation(const wxChar
*sz
)
460 wxLocale
*pLoc
= wxGetLocale();
462 return pLoc
->GetString(sz
);
464 return (const wxMB2WXbuf
)sz
;
469 // the macros should still be defined - otherwise compilation would fail
471 #if !defined(WXINTL_NO_GETTEXT_MACRO) && !defined(_)
475 #define wxTRANSLATE(str) _T(str)
477 inline const wxChar
*wxGetTranslation(const wxChar
*sz
) { return sz
; }
479 #endif // wxUSE_INTL/!wxUSE_INTL
481 // define this one just in case it occurs somewhere (instead of preferred
483 #if !defined(WXINTL_NO_GETTEXT_MACRO) && !defined(gettext_noop)
484 #define gettext_noop(str) _T(str)