Split wxLocale into wxLocale and wxTranslations.
[wxWidgets.git] / include / wx / intl.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/intl.h
3 // Purpose: Internationalization and localisation for wxWidgets
4 // Author: Vadim Zeitlin
5 // Modified by: Michael N. Filippov <michael@idisys.iae.nsk.su>
6 // (2003/09/30 - plural forms support)
7 // Created: 29/01/98
8 // RCS-ID: $Id$
9 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
12
13 // WARNING: Parts of this file are generated. See misc/languages/README for
14 // details.
15
16 #ifndef _WX_INTL_H_
17 #define _WX_INTL_H_
18
19 #include "wx/defs.h"
20 #include "wx/string.h"
21
22 #if !wxUSE_UNICODE
23 #include "wx/hashmap.h"
24 #endif
25
26 // Make wxLayoutDirection enum available without need for wxUSE_INTL so wxWindow, wxApp
27 // and other classes are not distrubed by wxUSE_INTL
28
29 enum wxLayoutDirection
30 {
31 wxLayout_Default,
32 wxLayout_LeftToRight,
33 wxLayout_RightToLeft
34 };
35
36 #if wxUSE_INTL
37
38 #include "wx/fontenc.h"
39
40 // ============================================================================
41 // global decls
42 // ============================================================================
43
44 // ----------------------------------------------------------------------------
45 // macros
46 // ----------------------------------------------------------------------------
47
48 // gettext() style macros (notice that xgettext should be invoked with
49 // --keyword="_" --keyword="wxPLURAL:1,2" options
50 // to extract the strings from the sources)
51 #ifndef WXINTL_NO_GETTEXT_MACRO
52 #define _(s) wxGetTranslation((s))
53 #define wxPLURAL(sing, plur, n) wxGetTranslation((sing), (plur), n)
54 #endif
55
56 // another one which just marks the strings for extraction, but doesn't
57 // perform the translation (use -kwxTRANSLATE with xgettext!)
58 #define wxTRANSLATE(str) str
59
60 // ----------------------------------------------------------------------------
61 // forward decls
62 // ----------------------------------------------------------------------------
63
64 class WXDLLIMPEXP_FWD_BASE wxTranslationsLoader;
65 class WXDLLIMPEXP_FWD_BASE wxLocale;
66 class WXDLLIMPEXP_FWD_BASE wxLanguageInfoArray;
67 class wxMsgCatalog;
68
69 // ============================================================================
70 // locale support
71 // ============================================================================
72
73 // ----------------------------------------------------------------------------
74 // wxLanguage: defines all supported languages
75 // ----------------------------------------------------------------------------
76
77 // --- --- --- generated code begins here --- --- ---
78
79 /**
80 The languages supported by wxLocale.
81
82 This enum is generated by misc/languages/genlang.py
83 When making changes, please put them into misc/languages/langtabl.txt
84 */
85 enum wxLanguage
86 {
87 /// User's default/preffered language as got from OS.
88 wxLANGUAGE_DEFAULT,
89
90 /// Unknown language, returned if wxLocale::GetSystemLanguage fails.
91 wxLANGUAGE_UNKNOWN,
92
93 wxLANGUAGE_ABKHAZIAN,
94 wxLANGUAGE_AFAR,
95 wxLANGUAGE_AFRIKAANS,
96 wxLANGUAGE_ALBANIAN,
97 wxLANGUAGE_AMHARIC,
98 wxLANGUAGE_ARABIC,
99 wxLANGUAGE_ARABIC_ALGERIA,
100 wxLANGUAGE_ARABIC_BAHRAIN,
101 wxLANGUAGE_ARABIC_EGYPT,
102 wxLANGUAGE_ARABIC_IRAQ,
103 wxLANGUAGE_ARABIC_JORDAN,
104 wxLANGUAGE_ARABIC_KUWAIT,
105 wxLANGUAGE_ARABIC_LEBANON,
106 wxLANGUAGE_ARABIC_LIBYA,
107 wxLANGUAGE_ARABIC_MOROCCO,
108 wxLANGUAGE_ARABIC_OMAN,
109 wxLANGUAGE_ARABIC_QATAR,
110 wxLANGUAGE_ARABIC_SAUDI_ARABIA,
111 wxLANGUAGE_ARABIC_SUDAN,
112 wxLANGUAGE_ARABIC_SYRIA,
113 wxLANGUAGE_ARABIC_TUNISIA,
114 wxLANGUAGE_ARABIC_UAE,
115 wxLANGUAGE_ARABIC_YEMEN,
116 wxLANGUAGE_ARMENIAN,
117 wxLANGUAGE_ASSAMESE,
118 wxLANGUAGE_ASTURIAN,
119 wxLANGUAGE_AYMARA,
120 wxLANGUAGE_AZERI,
121 wxLANGUAGE_AZERI_CYRILLIC,
122 wxLANGUAGE_AZERI_LATIN,
123 wxLANGUAGE_BASHKIR,
124 wxLANGUAGE_BASQUE,
125 wxLANGUAGE_BELARUSIAN,
126 wxLANGUAGE_BENGALI,
127 wxLANGUAGE_BHUTANI,
128 wxLANGUAGE_BIHARI,
129 wxLANGUAGE_BISLAMA,
130 wxLANGUAGE_BRETON,
131 wxLANGUAGE_BULGARIAN,
132 wxLANGUAGE_BURMESE,
133 wxLANGUAGE_CAMBODIAN,
134 wxLANGUAGE_CATALAN,
135 wxLANGUAGE_CHINESE,
136 wxLANGUAGE_CHINESE_SIMPLIFIED,
137 wxLANGUAGE_CHINESE_TRADITIONAL,
138 wxLANGUAGE_CHINESE_HONGKONG,
139 wxLANGUAGE_CHINESE_MACAU,
140 wxLANGUAGE_CHINESE_SINGAPORE,
141 wxLANGUAGE_CHINESE_TAIWAN,
142 wxLANGUAGE_CORSICAN,
143 wxLANGUAGE_CROATIAN,
144 wxLANGUAGE_CZECH,
145 wxLANGUAGE_DANISH,
146 wxLANGUAGE_DUTCH,
147 wxLANGUAGE_DUTCH_BELGIAN,
148 wxLANGUAGE_ENGLISH,
149 wxLANGUAGE_ENGLISH_UK,
150 wxLANGUAGE_ENGLISH_US,
151 wxLANGUAGE_ENGLISH_AUSTRALIA,
152 wxLANGUAGE_ENGLISH_BELIZE,
153 wxLANGUAGE_ENGLISH_BOTSWANA,
154 wxLANGUAGE_ENGLISH_CANADA,
155 wxLANGUAGE_ENGLISH_CARIBBEAN,
156 wxLANGUAGE_ENGLISH_DENMARK,
157 wxLANGUAGE_ENGLISH_EIRE,
158 wxLANGUAGE_ENGLISH_JAMAICA,
159 wxLANGUAGE_ENGLISH_NEW_ZEALAND,
160 wxLANGUAGE_ENGLISH_PHILIPPINES,
161 wxLANGUAGE_ENGLISH_SOUTH_AFRICA,
162 wxLANGUAGE_ENGLISH_TRINIDAD,
163 wxLANGUAGE_ENGLISH_ZIMBABWE,
164 wxLANGUAGE_ESPERANTO,
165 wxLANGUAGE_ESTONIAN,
166 wxLANGUAGE_FAEROESE,
167 wxLANGUAGE_FARSI,
168 wxLANGUAGE_FIJI,
169 wxLANGUAGE_FINNISH,
170 wxLANGUAGE_FRENCH,
171 wxLANGUAGE_FRENCH_BELGIAN,
172 wxLANGUAGE_FRENCH_CANADIAN,
173 wxLANGUAGE_FRENCH_LUXEMBOURG,
174 wxLANGUAGE_FRENCH_MONACO,
175 wxLANGUAGE_FRENCH_SWISS,
176 wxLANGUAGE_FRISIAN,
177 wxLANGUAGE_GALICIAN,
178 wxLANGUAGE_GEORGIAN,
179 wxLANGUAGE_GERMAN,
180 wxLANGUAGE_GERMAN_AUSTRIAN,
181 wxLANGUAGE_GERMAN_BELGIUM,
182 wxLANGUAGE_GERMAN_LIECHTENSTEIN,
183 wxLANGUAGE_GERMAN_LUXEMBOURG,
184 wxLANGUAGE_GERMAN_SWISS,
185 wxLANGUAGE_GREEK,
186 wxLANGUAGE_GREENLANDIC,
187 wxLANGUAGE_GUARANI,
188 wxLANGUAGE_GUJARATI,
189 wxLANGUAGE_HAUSA,
190 wxLANGUAGE_HEBREW,
191 wxLANGUAGE_HINDI,
192 wxLANGUAGE_HUNGARIAN,
193 wxLANGUAGE_ICELANDIC,
194 wxLANGUAGE_INDONESIAN,
195 wxLANGUAGE_INTERLINGUA,
196 wxLANGUAGE_INTERLINGUE,
197 wxLANGUAGE_INUKTITUT,
198 wxLANGUAGE_INUPIAK,
199 wxLANGUAGE_IRISH,
200 wxLANGUAGE_ITALIAN,
201 wxLANGUAGE_ITALIAN_SWISS,
202 wxLANGUAGE_JAPANESE,
203 wxLANGUAGE_JAVANESE,
204 wxLANGUAGE_KANNADA,
205 wxLANGUAGE_KASHMIRI,
206 wxLANGUAGE_KASHMIRI_INDIA,
207 wxLANGUAGE_KAZAKH,
208 wxLANGUAGE_KERNEWEK,
209 wxLANGUAGE_KINYARWANDA,
210 wxLANGUAGE_KIRGHIZ,
211 wxLANGUAGE_KIRUNDI,
212 wxLANGUAGE_KONKANI,
213 wxLANGUAGE_KOREAN,
214 wxLANGUAGE_KURDISH,
215 wxLANGUAGE_LAOTHIAN,
216 wxLANGUAGE_LATIN,
217 wxLANGUAGE_LATVIAN,
218 wxLANGUAGE_LINGALA,
219 wxLANGUAGE_LITHUANIAN,
220 wxLANGUAGE_MACEDONIAN,
221 wxLANGUAGE_MALAGASY,
222 wxLANGUAGE_MALAY,
223 wxLANGUAGE_MALAYALAM,
224 wxLANGUAGE_MALAY_BRUNEI_DARUSSALAM,
225 wxLANGUAGE_MALAY_MALAYSIA,
226 wxLANGUAGE_MALTESE,
227 wxLANGUAGE_MANIPURI,
228 wxLANGUAGE_MAORI,
229 wxLANGUAGE_MARATHI,
230 wxLANGUAGE_MOLDAVIAN,
231 wxLANGUAGE_MONGOLIAN,
232 wxLANGUAGE_NAURU,
233 wxLANGUAGE_NEPALI,
234 wxLANGUAGE_NEPALI_INDIA,
235 wxLANGUAGE_NORWEGIAN_BOKMAL,
236 wxLANGUAGE_NORWEGIAN_NYNORSK,
237 wxLANGUAGE_OCCITAN,
238 wxLANGUAGE_ORIYA,
239 wxLANGUAGE_OROMO,
240 wxLANGUAGE_PASHTO,
241 wxLANGUAGE_POLISH,
242 wxLANGUAGE_PORTUGUESE,
243 wxLANGUAGE_PORTUGUESE_BRAZILIAN,
244 wxLANGUAGE_PUNJABI,
245 wxLANGUAGE_QUECHUA,
246 wxLANGUAGE_RHAETO_ROMANCE,
247 wxLANGUAGE_ROMANIAN,
248 wxLANGUAGE_RUSSIAN,
249 wxLANGUAGE_RUSSIAN_UKRAINE,
250 wxLANGUAGE_SAMI,
251 wxLANGUAGE_SAMOAN,
252 wxLANGUAGE_SANGHO,
253 wxLANGUAGE_SANSKRIT,
254 wxLANGUAGE_SCOTS_GAELIC,
255 wxLANGUAGE_SERBIAN,
256 wxLANGUAGE_SERBIAN_CYRILLIC,
257 wxLANGUAGE_SERBIAN_LATIN,
258 wxLANGUAGE_SERBO_CROATIAN,
259 wxLANGUAGE_SESOTHO,
260 wxLANGUAGE_SETSWANA,
261 wxLANGUAGE_SHONA,
262 wxLANGUAGE_SINDHI,
263 wxLANGUAGE_SINHALESE,
264 wxLANGUAGE_SISWATI,
265 wxLANGUAGE_SLOVAK,
266 wxLANGUAGE_SLOVENIAN,
267 wxLANGUAGE_SOMALI,
268 wxLANGUAGE_SPANISH,
269 wxLANGUAGE_SPANISH_ARGENTINA,
270 wxLANGUAGE_SPANISH_BOLIVIA,
271 wxLANGUAGE_SPANISH_CHILE,
272 wxLANGUAGE_SPANISH_COLOMBIA,
273 wxLANGUAGE_SPANISH_COSTA_RICA,
274 wxLANGUAGE_SPANISH_DOMINICAN_REPUBLIC,
275 wxLANGUAGE_SPANISH_ECUADOR,
276 wxLANGUAGE_SPANISH_EL_SALVADOR,
277 wxLANGUAGE_SPANISH_GUATEMALA,
278 wxLANGUAGE_SPANISH_HONDURAS,
279 wxLANGUAGE_SPANISH_MEXICAN,
280 wxLANGUAGE_SPANISH_MODERN,
281 wxLANGUAGE_SPANISH_NICARAGUA,
282 wxLANGUAGE_SPANISH_PANAMA,
283 wxLANGUAGE_SPANISH_PARAGUAY,
284 wxLANGUAGE_SPANISH_PERU,
285 wxLANGUAGE_SPANISH_PUERTO_RICO,
286 wxLANGUAGE_SPANISH_URUGUAY,
287 wxLANGUAGE_SPANISH_US,
288 wxLANGUAGE_SPANISH_VENEZUELA,
289 wxLANGUAGE_SUNDANESE,
290 wxLANGUAGE_SWAHILI,
291 wxLANGUAGE_SWEDISH,
292 wxLANGUAGE_SWEDISH_FINLAND,
293 wxLANGUAGE_TAGALOG,
294 wxLANGUAGE_TAJIK,
295 wxLANGUAGE_TAMIL,
296 wxLANGUAGE_TATAR,
297 wxLANGUAGE_TELUGU,
298 wxLANGUAGE_THAI,
299 wxLANGUAGE_TIBETAN,
300 wxLANGUAGE_TIGRINYA,
301 wxLANGUAGE_TONGA,
302 wxLANGUAGE_TSONGA,
303 wxLANGUAGE_TURKISH,
304 wxLANGUAGE_TURKMEN,
305 wxLANGUAGE_TWI,
306 wxLANGUAGE_UIGHUR,
307 wxLANGUAGE_UKRAINIAN,
308 wxLANGUAGE_URDU,
309 wxLANGUAGE_URDU_INDIA,
310 wxLANGUAGE_URDU_PAKISTAN,
311 wxLANGUAGE_UZBEK,
312 wxLANGUAGE_UZBEK_CYRILLIC,
313 wxLANGUAGE_UZBEK_LATIN,
314 wxLANGUAGE_VALENCIAN,
315 wxLANGUAGE_VIETNAMESE,
316 wxLANGUAGE_VOLAPUK,
317 wxLANGUAGE_WELSH,
318 wxLANGUAGE_WOLOF,
319 wxLANGUAGE_XHOSA,
320 wxLANGUAGE_YIDDISH,
321 wxLANGUAGE_YORUBA,
322 wxLANGUAGE_ZHUANG,
323 wxLANGUAGE_ZULU,
324
325 /// For custom, user-defined languages.
326 wxLANGUAGE_USER_DEFINED
327 };
328
329 // --- --- --- generated code ends here --- --- ---
330
331 // ----------------------------------------------------------------------------
332 // wxLanguageInfo: encapsulates wxLanguage to OS native lang.desc.
333 // translation information
334 // ----------------------------------------------------------------------------
335
336 struct WXDLLIMPEXP_BASE wxLanguageInfo
337 {
338 int Language; // wxLanguage id
339 wxString CanonicalName; // Canonical name, e.g. fr_FR
340 #ifdef __WXMSW__
341 wxUint32 WinLang, // Win32 language identifiers
342 WinSublang;
343 #endif // __WXMSW__
344 wxString Description; // human-readable name of the language
345 wxLayoutDirection LayoutDirection;
346
347 #ifdef __WXMSW__
348 // return the LCID corresponding to this language
349 wxUint32 GetLCID() const;
350 #endif // __WXMSW__
351
352 // return the locale name corresponding to this language usable with
353 // setlocale() on the current system
354 wxString GetLocaleName() const;
355 };
356
357 // for Unix systems GetLocaleName() is trivial so implement it inline here, for
358 // MSW it's implemented in intl.cpp
359 #ifndef __WXMSW__
360 inline wxString wxLanguageInfo::GetLocaleName() const { return CanonicalName; }
361 #endif // !__WXMSW__
362
363 // ----------------------------------------------------------------------------
364 // wxTranslations: message catalogs
365 // ----------------------------------------------------------------------------
366
367 // this class allows to get translations for strings
368 class WXDLLIMPEXP_BASE wxTranslations
369 {
370 public:
371 wxTranslations();
372 ~wxTranslations();
373
374 // returns current translations object, may return NULL
375 static wxTranslations *Get();
376 // sets current translations object (takes ownership; may be NULL)
377 static void Set(wxTranslations *t);
378
379 // changes loader to non-default one; takes ownership of 'loader'
380 void SetLoader(wxTranslationsLoader *loader);
381
382 void SetLanguage(wxLanguage lang);
383 void SetLanguage(const wxString& lang);
384
385 // add standard wxWidgets catalog ("wxstd")
386 bool AddStdCatalog();
387
388 // add catalog with given domain name and language, looking it up via
389 // wxTranslationsLoader
390 bool AddCatalog(const wxString& domain);
391 bool AddCatalog(const wxString& domain, wxLanguage msgIdLanguage);
392 #if !wxUSE_UNICODE
393 bool AddCatalog(const wxString& domain,
394 wxLanguage msgIdLanguage,
395 const wxString& msgIdCharset);
396 #endif
397
398 // check if the given catalog is loaded
399 bool IsLoaded(const wxString& domain) const;
400
401 // load catalog data directly from file
402 bool LoadCatalogFile(const wxString& filename,
403 const wxString& domain = wxEmptyString);
404
405 // access to translations
406 const wxString& GetString(const wxString& origString,
407 const wxString& domain = wxEmptyString) const;
408 const wxString& GetString(const wxString& origString,
409 const wxString& origString2,
410 size_t n,
411 const wxString& domain = wxEmptyString) const;
412
413 wxString GetHeaderValue(const wxString& header,
414 const wxString& domain = wxEmptyString) const;
415
416 // this is hack to work around a problem with wxGetTranslation() which
417 // returns const wxString& and not wxString, so when it returns untranslated
418 // string, it needs to have a copy of it somewhere
419 static const wxString& GetUntranslatedString(const wxString& str);
420
421 private:
422 // find best translation for given domain
423 wxString ChooseLanguageForDomain(const wxString& domain,
424 const wxString& msgIdLang);
425
426 // find catalog by name in a linked list, return NULL if !found
427 wxMsgCatalog *FindCatalog(const wxString& domain) const;
428
429 // same as Set(), without taking ownership; only for wxLocale
430 static void SetNonOwned(wxTranslations *t);
431 friend class wxLocale;
432
433 private:
434 wxString m_lang;
435 wxTranslationsLoader *m_loader;
436
437 wxMsgCatalog *m_pMsgCat; // pointer to linked list of catalogs
438
439 #if !wxUSE_UNICODE
440 wxStringToStringHashMap m_msgIdCharset;
441 #endif
442 };
443
444
445 // abstraction of translations discovery and loading
446 class WXDLLIMPEXP_BASE wxTranslationsLoader
447 {
448 public:
449 wxTranslationsLoader() {}
450 virtual ~wxTranslationsLoader() {}
451
452 virtual bool LoadCatalog(wxTranslations *translations,
453 const wxString& domain, const wxString& lang) = 0;
454 };
455
456 // standard wxTranslationsLoader implementation, using filesystem
457 class WXDLLIMPEXP_BASE wxFileTranslationsLoader
458 : public wxTranslationsLoader
459 {
460 public:
461 static void AddCatalogLookupPathPrefix(const wxString& prefix);
462
463 virtual bool LoadCatalog(wxTranslations *translations,
464 const wxString& domain, const wxString& lang);
465 };
466
467
468 // ----------------------------------------------------------------------------
469 // wxLocaleCategory: the category of locale settings
470 // ----------------------------------------------------------------------------
471
472 enum wxLocaleCategory
473 {
474 // (any) numbers
475 wxLOCALE_CAT_NUMBER,
476
477 // date/time
478 wxLOCALE_CAT_DATE,
479
480 // monetary value
481 wxLOCALE_CAT_MONEY,
482
483 // default category for wxLocaleInfo values which only apply to a single
484 // category (e.g. wxLOCALE_SHORT_DATE_FMT)
485 wxLOCALE_CAT_DEFAULT,
486
487 wxLOCALE_CAT_MAX
488 };
489
490 // ----------------------------------------------------------------------------
491 // wxLocaleInfo: the items understood by wxLocale::GetInfo()
492 // ----------------------------------------------------------------------------
493
494 enum wxLocaleInfo
495 {
496 // the thousands separator (for wxLOCALE_CAT_NUMBER or MONEY)
497 wxLOCALE_THOUSANDS_SEP,
498
499 // the character used as decimal point (for wxLOCALE_CAT_NUMBER or MONEY)
500 wxLOCALE_DECIMAL_POINT,
501
502 // the stftime()-formats used for short/long date and time representations
503 // (under some platforms short and long date formats are the same)
504 //
505 // NB: these elements should appear in this order, code in GetInfo() relies
506 // on it
507 wxLOCALE_SHORT_DATE_FMT,
508 wxLOCALE_LONG_DATE_FMT,
509 wxLOCALE_DATE_TIME_FMT,
510 wxLOCALE_TIME_FMT
511
512 };
513
514 // ----------------------------------------------------------------------------
515 // wxLocale: encapsulates all language dependent settings, including current
516 // message catalogs, date, time and currency formats (TODO) &c
517 // ----------------------------------------------------------------------------
518
519 enum wxLocaleInitFlags
520 {
521 wxLOCALE_DONT_LOAD_DEFAULT = 0x0000, // don't load wxwin.mo
522 wxLOCALE_LOAD_DEFAULT = 0x0001 // load wxwin.mo?
523 #if WXWIN_COMPATIBILITY_2_8
524 ,wxLOCALE_CONV_ENCODING = 0x0002 // no longer used, simply remove
525 // it from the existing code
526 #endif
527 };
528
529 class WXDLLIMPEXP_BASE wxLocale
530 {
531 public:
532 // ctor & dtor
533 // -----------
534
535 // call Init() if you use this ctor
536 wxLocale() { DoCommonInit(); }
537
538 // the ctor has a side effect of changing current locale
539 wxLocale(const wxString& name, // name (for messages)
540 const wxString& shortName = wxEmptyString, // dir prefix (for msg files)
541 const wxString& locale = wxEmptyString, // locale (for setlocale)
542 bool bLoadDefault = true // preload wxstd.mo?
543 #if WXWIN_COMPATIBILITY_2_8
544 ,bool bConvertEncoding = true // convert Win<->Unix if necessary?
545 #endif
546 )
547 {
548 DoCommonInit();
549
550 #if WXWIN_COMPATIBILITY_2_8
551 Init(name, shortName, locale, bLoadDefault, bConvertEncoding);
552 #else
553 Init(name, shortName, locale, bLoadDefault);
554 #endif
555 }
556
557 wxLocale(int language, // wxLanguage id or custom language
558 int flags = wxLOCALE_LOAD_DEFAULT)
559 {
560 DoCommonInit();
561
562 Init(language, flags);
563 }
564
565 // the same as a function (returns true on success)
566 bool Init(const wxString& name,
567 const wxString& shortName = wxEmptyString,
568 const wxString& locale = wxEmptyString,
569 bool bLoadDefault = true
570 #if WXWIN_COMPATIBILITY_2_8
571 ,bool bConvertEncoding = true
572 #endif
573 );
574
575 // same as second ctor (returns true on success)
576 bool Init(int language = wxLANGUAGE_DEFAULT,
577 int flags = wxLOCALE_LOAD_DEFAULT);
578
579 // restores old locale
580 virtual ~wxLocale();
581
582 // Try to get user's (or OS's) preferred language setting.
583 // Return wxLANGUAGE_UNKNOWN if language-guessing algorithm failed
584 static int GetSystemLanguage();
585
586 // get the encoding used by default for text on this system, returns
587 // wxFONTENCODING_SYSTEM if it couldn't be determined
588 static wxFontEncoding GetSystemEncoding();
589
590 // get the string describing the system encoding, return empty string if
591 // couldn't be determined
592 static wxString GetSystemEncodingName();
593
594 // get the values of the given locale-dependent datum: the current locale
595 // is used, the US default value is returned if everything else fails
596 static wxString GetInfo(wxLocaleInfo index,
597 wxLocaleCategory cat = wxLOCALE_CAT_DEFAULT);
598
599 // return true if the locale was set successfully
600 bool IsOk() const { return m_pszOldLocale != NULL; }
601
602 // returns locale name
603 const wxString& GetLocale() const { return m_strLocale; }
604
605 // return current locale wxLanguage value
606 int GetLanguage() const { return m_language; }
607
608 // return locale name to be passed to setlocale()
609 wxString GetSysName() const;
610
611 // return 'canonical' name, i.e. in the form of xx[_YY], where xx is
612 // language code according to ISO 639 and YY is country name
613 // as specified by ISO 3166.
614 wxString GetCanonicalName() const { return m_strShort; }
615
616 // add a prefix to the catalog lookup path: the message catalog files will be
617 // looked up under prefix/<lang>/LC_MESSAGES, prefix/LC_MESSAGES and prefix
618 // (in this order).
619 //
620 // This only applies to subsequent invocations of AddCatalog()!
621 static void AddCatalogLookupPathPrefix(const wxString& prefix)
622 { wxFileTranslationsLoader::AddCatalogLookupPathPrefix(prefix); }
623
624 // add a catalog: it's searched for in standard places (current directory
625 // first, system one after), but the you may prepend additional directories to
626 // the search path with AddCatalogLookupPathPrefix().
627 //
628 // The loaded catalog will be used for message lookup by GetString().
629 //
630 // Returns 'true' if it was successfully loaded
631 bool AddCatalog(const wxString& domain)
632 { return m_translations.AddCatalog(domain); }
633 bool AddCatalog(const wxString& domain, wxLanguage msgIdLanguage)
634 { return m_translations.AddCatalog(domain, msgIdLanguage); }
635 bool AddCatalog(const wxString& domain,
636 wxLanguage msgIdLanguage, const wxString& msgIdCharset);
637
638 // check if the given locale is provided by OS and C run time
639 static bool IsAvailable(int lang);
640
641 // check if the given catalog is loaded
642 bool IsLoaded(const wxString& domain) const
643 { return m_translations.IsLoaded(domain); }
644
645 // Retrieve the language info struct for the given language
646 //
647 // Returns NULL if no info found, pointer must *not* be deleted by caller
648 static const wxLanguageInfo *GetLanguageInfo(int lang);
649
650 // Returns language name in English or empty string if the language
651 // is not in database
652 static wxString GetLanguageName(int lang);
653
654 // Returns ISO code ("canonical name") of language or empty string if the
655 // language is not in database
656 static wxString GetLanguageCanonicalName(int lang);
657
658 // Find the language for the given locale string which may be either a
659 // canonical ISO 2 letter language code ("xx"), a language code followed by
660 // the country code ("xx_XX") or a Windows full language name ("Xxxxx...")
661 //
662 // Returns NULL if no info found, pointer must *not* be deleted by caller
663 static const wxLanguageInfo *FindLanguageInfo(const wxString& locale);
664
665 // Add custom language to the list of known languages.
666 // Notes: 1) wxLanguageInfo contains platform-specific data
667 // 2) must be called before Init to have effect
668 static void AddLanguage(const wxLanguageInfo& info);
669
670 // retrieve the translation for a string in all loaded domains unless
671 // the szDomain parameter is specified (and then only this domain is
672 // searched)
673 // n - additional parameter for PluralFormsParser
674 //
675 // return original string if translation is not available
676 // (in this case an error message is generated the first time
677 // a string is not found; use wxLogNull to suppress it)
678 //
679 // domains are searched in the last to first order, i.e. catalogs
680 // added later override those added before.
681 const wxString& GetString(const wxString& origString,
682 const wxString& domain = wxEmptyString) const
683 {
684 return m_translations.GetString(origString, domain);
685 }
686 // plural form version of the same:
687 const wxString& GetString(const wxString& origString,
688 const wxString& origString2,
689 size_t n,
690 const wxString& domain = wxEmptyString) const
691 {
692 return m_translations.GetString(origString, origString2, n, domain);
693 }
694
695 // this is hack to work around a problem with wxGetTranslation() which
696 // returns const wxString& and not wxString, so when it returns untranslated
697 // string, it needs to have a copy of it somewhere
698 static const wxString& GetUntranslatedString(const wxString& str)
699 { return wxTranslations::GetUntranslatedString(str); }
700
701 // Returns the current short name for the locale
702 const wxString& GetName() const { return m_strShort; }
703
704 // return the contents of .po file header
705 wxString GetHeaderValue(const wxString& header,
706 const wxString& domain = wxEmptyString) const
707 {
708 return m_translations.GetHeaderValue(header, domain);
709 }
710
711 // These two methods are for internal use only. First one creates
712 // ms_languagesDB if it doesn't already exist, second one destroys
713 // it.
714 static void CreateLanguagesDB();
715 static void DestroyLanguagesDB();
716
717 private:
718 bool DoInit(const wxString& name,
719 const wxString& shortName,
720 const wxString& locale);
721
722 // copy default table of languages from global static array to
723 // m_langugagesInfo, called by InitLanguagesDB
724 static void InitLanguagesDB();
725
726 // initialize the member fields to default values
727 void DoCommonInit();
728
729 wxString m_strLocale, // this locale name
730 m_strShort; // short name for the locale
731 int m_language; // this locale wxLanguage value
732
733 const char *m_pszOldLocale; // previous locale from setlocale()
734 wxLocale *m_pOldLocale; // previous wxLocale
735
736 bool m_initialized;
737
738 wxTranslations m_translations;
739
740 static wxLanguageInfoArray *ms_languagesDB;
741
742 wxDECLARE_NO_COPY_CLASS(wxLocale);
743 };
744
745 // ----------------------------------------------------------------------------
746 // global functions
747 // ----------------------------------------------------------------------------
748
749 // get the current locale object (note that it may be NULL!)
750 extern WXDLLIMPEXP_BASE wxLocale* wxGetLocale();
751
752 // get the translation of the string in the current locale
753 inline const wxString& wxGetTranslation(const wxString& str,
754 const wxString& domain = wxEmptyString)
755 {
756 wxTranslations *trans = wxTranslations::Get();
757 if ( trans )
758 return trans->GetString(str, domain);
759 else
760 // NB: this function returns reference to a string, so we have to keep
761 // a copy of it somewhere
762 return wxTranslations::GetUntranslatedString(str);
763 }
764 inline const wxString& wxGetTranslation(const wxString& str1,
765 const wxString& str2,
766 size_t n,
767 const wxString& domain = wxEmptyString)
768 {
769 wxTranslations *trans = wxTranslations::Get();
770 if ( trans )
771 return trans->GetString(str1, str2, n, domain);
772 else
773 // NB: this function returns reference to a string, so we have to keep
774 // a copy of it somewhere
775 return n == 1
776 ? wxTranslations::GetUntranslatedString(str1)
777 : wxTranslations::GetUntranslatedString(str2);
778 }
779
780 #else // !wxUSE_INTL
781
782 // the macros should still be defined - otherwise compilation would fail
783
784 #if !defined(WXINTL_NO_GETTEXT_MACRO)
785 #if !defined(_)
786 #define _(s) (s)
787 #endif
788 #define wxPLURAL(sing, plur, n) ((n) == 1 ? (sing) : (plur))
789 #endif
790
791 #define wxTRANSLATE(str) str
792
793 // NB: we use a template here in order to avoid using
794 // wxLocale::GetUntranslatedString() above, which would be required if
795 // we returned const wxString&; this way, the compiler should be able to
796 // optimize wxGetTranslation() away
797
798 template<typename TString>
799 inline TString wxGetTranslation(TString str)
800 { return str; }
801
802 template<typename TString, typename TDomain>
803 inline TString wxGetTranslation(TString str, TDomain WXUNUSED(domain))
804 { return str; }
805
806 template<typename TString, typename TDomain>
807 inline TString wxGetTranslation(TString str1, TString str2, size_t n)
808 { return n == 1 ? str1 : str2; }
809
810 template<typename TString, typename TDomain>
811 inline TString wxGetTranslation(TString str1, TString str2, size_t n,
812 TDomain WXUNUSED(domain))
813 { return n == 1 ? str1 : str2; }
814
815 #endif // wxUSE_INTL/!wxUSE_INTL
816
817 // define this one just in case it occurs somewhere (instead of preferred
818 // wxTRANSLATE) too
819 #if !defined(WXINTL_NO_GETTEXT_MACRO)
820 #if !defined(gettext_noop)
821 #define gettext_noop(str) (str)
822 #endif
823 #if !defined(N_)
824 #define N_(s) (s)
825 #endif
826 #endif
827
828 #endif // _WX_INTL_H_