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