]> git.saurik.com Git - wxWidgets.git/blob - include/wx/intl.h
textctrl is now coded.
[wxWidgets.git] / include / wx / intl.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/intl.h
3 // Purpose: Internationalization and localisation for wxWindows
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 29/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef __INTLH__
13 #define __INTLH__
14
15 #ifdef __GNUG__
16 #pragma interface "intl.h"
17 #endif
18
19 #include "wx/defs.h"
20 #include "wx/string.h"
21
22 #if wxUSE_INTL
23
24 // ============================================================================
25 // global decls
26 // ============================================================================
27
28 // ----------------------------------------------------------------------------
29 // macros
30 // ----------------------------------------------------------------------------
31
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))
36 #endif
37
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)
41
42 // ----------------------------------------------------------------------------
43 // forward decls
44 // ----------------------------------------------------------------------------
45
46 class WXDLLEXPORT wxLocale;
47 class WXDLLEXPORT wxMsgCatalog;
48 class WXDLLEXPORT wxLanguageInfoArray;
49
50 // ============================================================================
51 // locale support
52 // ============================================================================
53
54 // ----------------------------------------------------------------------------
55 // wxLanguage: defines all supported languages
56 // ----------------------------------------------------------------------------
57
58 // --- --- --- generated code begins here --- --- ---
59
60 // This enum is generated by misc/languages/genlang.py
61 // When making changes, please put them into misc/languages/langtabl.txt
62 enum wxLanguage
63 {
64 // user's default/preffered language as got from OS:
65 wxLANGUAGE_DEFAULT,
66 // unknown language, if wxLocale::GetSystemLanguage fails:
67 wxLANGUAGE_UNKNOWN,
68
69 wxLANGUAGE_ABKHAZIAN,
70 wxLANGUAGE_AFAR,
71 wxLANGUAGE_AFRIKAANS,
72 wxLANGUAGE_ALBANIAN,
73 wxLANGUAGE_AMHARIC,
74 wxLANGUAGE_ARABIC,
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,
92 wxLANGUAGE_ARMENIAN,
93 wxLANGUAGE_ASSAMESE,
94 wxLANGUAGE_AYMARA,
95 wxLANGUAGE_AZERI,
96 wxLANGUAGE_AZERI_CYRILLIC,
97 wxLANGUAGE_AZERI_LATIN,
98 wxLANGUAGE_BASHKIR,
99 wxLANGUAGE_BASQUE,
100 wxLANGUAGE_BELARUSIAN,
101 wxLANGUAGE_BENGALI,
102 wxLANGUAGE_BHUTANI,
103 wxLANGUAGE_BIHARI,
104 wxLANGUAGE_BISLAMA,
105 wxLANGUAGE_BRETON,
106 wxLANGUAGE_BULGARIAN,
107 wxLANGUAGE_BURMESE,
108 wxLANGUAGE_CAMBODIAN,
109 wxLANGUAGE_CATALAN,
110 wxLANGUAGE_CHINESE,
111 wxLANGUAGE_CHINESE_SIMPLIFIED,
112 wxLANGUAGE_CHINESE_TRADITIONAL,
113 wxLANGUAGE_CHINESE_HONGKONG,
114 wxLANGUAGE_CHINESE_MACAU,
115 wxLANGUAGE_CHINESE_SINGAPORE,
116 wxLANGUAGE_CHINESE_TAIWAN,
117 wxLANGUAGE_CORSICAN,
118 wxLANGUAGE_CROATIAN,
119 wxLANGUAGE_CZECH,
120 wxLANGUAGE_DANISH,
121 wxLANGUAGE_DUTCH,
122 wxLANGUAGE_DUTCH_BELGIAN,
123 wxLANGUAGE_ENGLISH,
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,
140 wxLANGUAGE_ESTONIAN,
141 wxLANGUAGE_FAEROESE,
142 wxLANGUAGE_FARSI,
143 wxLANGUAGE_FIJI,
144 wxLANGUAGE_FINNISH,
145 wxLANGUAGE_FRENCH,
146 wxLANGUAGE_FRENCH_BELGIAN,
147 wxLANGUAGE_FRENCH_CANADIAN,
148 wxLANGUAGE_FRENCH_LUXEMBOURG,
149 wxLANGUAGE_FRENCH_MONACO,
150 wxLANGUAGE_FRENCH_SWISS,
151 wxLANGUAGE_FRISIAN,
152 wxLANGUAGE_GALICIAN,
153 wxLANGUAGE_GEORGIAN,
154 wxLANGUAGE_GERMAN,
155 wxLANGUAGE_GERMAN_AUSTRIAN,
156 wxLANGUAGE_GERMAN_BELGIUM,
157 wxLANGUAGE_GERMAN_LIECHTENSTEIN,
158 wxLANGUAGE_GERMAN_LUXEMBOURG,
159 wxLANGUAGE_GERMAN_SWISS,
160 wxLANGUAGE_GREEK,
161 wxLANGUAGE_GREENLANDIC,
162 wxLANGUAGE_GUARANI,
163 wxLANGUAGE_GUJARATI,
164 wxLANGUAGE_HAUSA,
165 wxLANGUAGE_HEBREW,
166 wxLANGUAGE_HINDI,
167 wxLANGUAGE_HUNGARIAN,
168 wxLANGUAGE_ICELANDIC,
169 wxLANGUAGE_INDONESIAN,
170 wxLANGUAGE_INTERLINGUA,
171 wxLANGUAGE_INTERLINGUE,
172 wxLANGUAGE_INUKTITUT,
173 wxLANGUAGE_INUPIAK,
174 wxLANGUAGE_IRISH,
175 wxLANGUAGE_ITALIAN,
176 wxLANGUAGE_ITALIAN_SWISS,
177 wxLANGUAGE_JAPANESE,
178 wxLANGUAGE_JAVANESE,
179 wxLANGUAGE_KANNADA,
180 wxLANGUAGE_KASHMIRI,
181 wxLANGUAGE_KASHMIRI_INDIA,
182 wxLANGUAGE_KAZAKH,
183 wxLANGUAGE_KERNEWEK,
184 wxLANGUAGE_KINYARWANDA,
185 wxLANGUAGE_KIRGHIZ,
186 wxLANGUAGE_KIRUNDI,
187 wxLANGUAGE_KONKANI,
188 wxLANGUAGE_KOREAN,
189 wxLANGUAGE_KURDISH,
190 wxLANGUAGE_LAOTHIAN,
191 wxLANGUAGE_LATIN,
192 wxLANGUAGE_LATVIAN,
193 wxLANGUAGE_LINGALA,
194 wxLANGUAGE_LITHUANIAN,
195 wxLANGUAGE_MACEDONIAN,
196 wxLANGUAGE_MALAGASY,
197 wxLANGUAGE_MALAY,
198 wxLANGUAGE_MALAYALAM,
199 wxLANGUAGE_MALAY_BRUNEI_DARUSSALAM,
200 wxLANGUAGE_MALAY_MALAYSIA,
201 wxLANGUAGE_MALTESE,
202 wxLANGUAGE_MANIPURI,
203 wxLANGUAGE_MAORI,
204 wxLANGUAGE_MARATHI,
205 wxLANGUAGE_MOLDAVIAN,
206 wxLANGUAGE_MONGOLIAN,
207 wxLANGUAGE_NAURU,
208 wxLANGUAGE_NEPALI,
209 wxLANGUAGE_NEPALI_INDIA,
210 wxLANGUAGE_NORWEGIAN_BOKMAL,
211 wxLANGUAGE_NORWEGIAN_NYNORSK,
212 wxLANGUAGE_OCCITAN,
213 wxLANGUAGE_ORIYA,
214 wxLANGUAGE_OROMO,
215 wxLANGUAGE_PASHTO,
216 wxLANGUAGE_POLISH,
217 wxLANGUAGE_PORTUGUESE,
218 wxLANGUAGE_PORTUGUESE_BRAZILIAN,
219 wxLANGUAGE_PUNJABI,
220 wxLANGUAGE_QUECHUA,
221 wxLANGUAGE_RHAETO_ROMANCE,
222 wxLANGUAGE_ROMANIAN,
223 wxLANGUAGE_RUSSIAN,
224 wxLANGUAGE_RUSSIAN_UKRAINE,
225 wxLANGUAGE_SAMOAN,
226 wxLANGUAGE_SANGHO,
227 wxLANGUAGE_SANSKRIT,
228 wxLANGUAGE_SCOTS_GAELIC,
229 wxLANGUAGE_SERBIAN,
230 wxLANGUAGE_SERBIAN_CYRILLIC,
231 wxLANGUAGE_SERBIAN_LATIN,
232 wxLANGUAGE_SERBO_CROATIAN,
233 wxLANGUAGE_SESOTHO,
234 wxLANGUAGE_SETSWANA,
235 wxLANGUAGE_SHONA,
236 wxLANGUAGE_SINDHI,
237 wxLANGUAGE_SINHALESE,
238 wxLANGUAGE_SISWATI,
239 wxLANGUAGE_SLOVAK,
240 wxLANGUAGE_SLOVENIAN,
241 wxLANGUAGE_SOMALI,
242 wxLANGUAGE_SPANISH,
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,
264 wxLANGUAGE_SWAHILI,
265 wxLANGUAGE_SWEDISH,
266 wxLANGUAGE_SWEDISH_FINLAND,
267 wxLANGUAGE_TAGALOG,
268 wxLANGUAGE_TAJIK,
269 wxLANGUAGE_TAMIL,
270 wxLANGUAGE_TATAR,
271 wxLANGUAGE_TELUGU,
272 wxLANGUAGE_THAI,
273 wxLANGUAGE_TIBETAN,
274 wxLANGUAGE_TIGRINYA,
275 wxLANGUAGE_TONGA,
276 wxLANGUAGE_TSONGA,
277 wxLANGUAGE_TURKISH,
278 wxLANGUAGE_TURKMEN,
279 wxLANGUAGE_TWI,
280 wxLANGUAGE_UIGHUR,
281 wxLANGUAGE_UKRAINIAN,
282 wxLANGUAGE_URDU,
283 wxLANGUAGE_URDU_INDIA,
284 wxLANGUAGE_URDU_PAKISTAN,
285 wxLANGUAGE_UZBEK,
286 wxLANGUAGE_UZBEK_CYRILLIC,
287 wxLANGUAGE_UZBEK_LATIN,
288 wxLANGUAGE_VIETNAMESE,
289 wxLANGUAGE_VOLAPUK,
290 wxLANGUAGE_WELSH,
291 wxLANGUAGE_WOLOF,
292 wxLANGUAGE_XHOSA,
293 wxLANGUAGE_YIDDISH,
294 wxLANGUAGE_YORUBA,
295 wxLANGUAGE_ZHUANG,
296 wxLANGUAGE_ZULU,
297
298 // for custom, user-defined languages:
299 wxLANGUAGE_USER_DEFINED
300 };
301
302 // --- --- --- generated code ends here --- --- ---
303
304
305
306 // ----------------------------------------------------------------------------
307 // wxLanguageInfo: encapsulates wxLanguage to OS native lang.desc.
308 // translation information
309 // ----------------------------------------------------------------------------
310
311 struct WXDLLEXPORT wxLanguageInfo
312 {
313 int Language; // wxLanguage id
314 wxString CanonicalName; // Canonical name, e.g. fr_FR
315 #ifdef __WIN32__
316 wxUint32 WinLang, WinSublang; // Win32 language identifiers
317 #endif
318 wxString Description; // human-readable name of the language
319 };
320
321 // ----------------------------------------------------------------------------
322 // wxLocale: encapsulates all language dependent settings, including current
323 // message catalogs, date, time and currency formats (TODO) &c
324 // ----------------------------------------------------------------------------
325
326 enum wxLocaleInitFlags
327 {
328 wxLOCALE_LOAD_DEFAULT = 0x0001, // load wxwin.mo?
329 wxLOCALE_CONV_ENCODING = 0x0002 // convert encoding on the fly?
330 };
331
332
333 class WXDLLEXPORT wxLocale
334 {
335 public:
336 // ctor & dtor
337 // -----------
338
339 // call Init() if you use this ctor
340 wxLocale();
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?
347 {
348 Init(szName, szShort, szLocale, bLoadDefault, bConvertEncoding);
349 }
350
351 wxLocale(int language, // wxLanguage id or custom language
352 int flags = wxLOCALE_LOAD_DEFAULT | wxLOCALE_CONV_ENCODING)
353 { Init(language, flags); }
354
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);
361
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);
365
366 // restores old locale
367 ~wxLocale();
368
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();
372
373 // return TRUE if the locale was set successfully
374 bool IsOk() const { return m_pszOldLocale != NULL; }
375
376 // returns locale name
377 const wxChar *GetLocale() const { return m_strLocale; }
378
379 // return current locale wxLanguage value
380 int GetLanguage() const { return m_language; }
381
382 // return locale name to be passed to setlocale()
383 wxString GetSysName() const;
384
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; }
389
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
392 // (in this order).
393 //
394 // This only applies to subsequent invocations of AddCatalog()!
395 static void AddCatalogLookupPathPrefix(const wxString& prefix);
396
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().
400 //
401 // The loaded catalog will be used for message lookup by GetString().
402 //
403 // Returns 'true' if it was successfully loaded
404 bool AddCatalog(const wxChar *szDomain);
405
406 // check if the given catalog is loaded
407 bool IsLoaded(const wxChar *szDomain) const;
408
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);
413
414 // retrieve the translation for a string in all loaded domains unless
415 // the szDomain parameter is specified (and then only this domain is
416 // searched)
417 //
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)
421 //
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;
426
427 // Returns the current short name for the locale
428 const wxString& GetName() const { return m_strShort; }
429
430 // These two methods are for internal use only. First one creates
431 // ms_languagesDB if it doesn't already exist, second one destroys
432 // it.
433 static void CreateLanguagesDB();
434 static void DestroyLanguagesDB();
435
436 private:
437 // find catalog by name in a linked list, return NULL if !found
438 wxMsgCatalog *FindCatalog(const wxChar *szDomain) const;
439
440 // copy default table of languages from global static array to
441 // m_langugagesInfo, called by InitLanguagesDB
442 static void InitLanguagesDB();
443
444 wxString m_strLocale, // this locale name
445 m_strShort; // short name for the locale
446 int m_language; // this locale wxLanguage value
447
448 const wxChar *m_pszOldLocale; // previous locale from setlocale()
449 wxLocale *m_pOldLocale; // previous wxLocale
450
451 wxMsgCatalog *m_pMsgCat; // pointer to linked list of catalogs
452
453 bool m_bConvertEncoding;
454
455 static wxLanguageInfoArray *ms_languagesDB;
456 };
457
458 // ----------------------------------------------------------------------------
459 // global functions
460 // ----------------------------------------------------------------------------
461
462 // get the current locale object (note that it may be NULL!)
463 extern WXDLLEXPORT wxLocale* wxGetLocale();
464
465 // get the translation of the string in the current locale
466 inline const wxMB2WXbuf wxGetTranslation(const wxChar *sz)
467 {
468 wxLocale *pLoc = wxGetLocale();
469 if (pLoc)
470 return pLoc->GetString(sz);
471 else
472 return (const wxMB2WXbuf)sz;
473 }
474
475 #else // !wxUSE_INTL
476
477 // the macros should still be defined - otherwise compilation would fail
478
479 #if !defined(WXINTL_NO_GETTEXT_MACRO) && !defined(_)
480 #define _(str) (str)
481 #endif
482
483 #define wxTRANSLATE(str) _T(str)
484
485 inline const wxChar *wxGetTranslation(const wxChar *sz) { return sz; }
486
487 #endif // wxUSE_INTL/!wxUSE_INTL
488
489 // define this one just in case it occurs somewhere (instead of preferred
490 // wxTRANSLATE) too
491 #if !defined(WXINTL_NO_GETTEXT_MACRO) && !defined(gettext_noop)
492 #define gettext_noop(str) _T(str)
493 #endif
494
495 #endif
496 // _WX_INTLH__