]>
Commit | Line | Data |
---|---|---|
c801d85f | 1 | ///////////////////////////////////////////////////////////////////////////// |
58d5dfc1 | 2 | // Name: wx/intl.h |
77ffb593 | 3 | // Purpose: Internationalization and localisation for wxWidgets |
c801d85f | 4 | // Author: Vadim Zeitlin |
849a28d0 VS |
5 | // Modified by: Michael N. Filippov <michael@idisys.iae.nsk.su> |
6 | // (2003/09/30 - plural forms support) | |
c801d85f KB |
7 | // Created: 29/01/98 |
8 | // RCS-ID: $Id$ | |
9 | // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr> | |
65571936 | 10 | // Licence: wxWindows licence |
c801d85f KB |
11 | ///////////////////////////////////////////////////////////////////////////// |
12 | ||
dccce9ea VZ |
13 | #ifndef _WX_INTL_H_ |
14 | #define _WX_INTL_H_ | |
c801d85f | 15 | |
c801d85f KB |
16 | #include "wx/defs.h" |
17 | #include "wx/string.h" | |
ea144923 | 18 | #include "wx/translation.h" |
18e065b4 | 19 | |
b137e493 WS |
20 | // Make wxLayoutDirection enum available without need for wxUSE_INTL so wxWindow, wxApp |
21 | // and other classes are not distrubed by wxUSE_INTL | |
22 | ||
23 | enum wxLayoutDirection | |
24 | { | |
25 | wxLayout_Default, | |
26 | wxLayout_LeftToRight, | |
27 | wxLayout_RightToLeft | |
28 | }; | |
29 | ||
88ac883a VZ |
30 | #if wxUSE_INTL |
31 | ||
dccce9ea | 32 | #include "wx/fontenc.h" |
ea144923 | 33 | #include "wx/language.h" |
dccce9ea | 34 | |
c801d85f KB |
35 | // ============================================================================ |
36 | // global decls | |
37 | // ============================================================================ | |
38 | ||
c801d85f KB |
39 | // ---------------------------------------------------------------------------- |
40 | // macros | |
41 | // ---------------------------------------------------------------------------- | |
42 | ||
c801d85f KB |
43 | // ---------------------------------------------------------------------------- |
44 | // forward decls | |
45 | // ---------------------------------------------------------------------------- | |
ec37df57 | 46 | |
b5dbe15d VS |
47 | class WXDLLIMPEXP_FWD_BASE wxLocale; |
48 | class WXDLLIMPEXP_FWD_BASE wxLanguageInfoArray; | |
c801d85f KB |
49 | |
50 | // ============================================================================ | |
51 | // locale support | |
52 | // ============================================================================ | |
53 | ||
fda91381 VS |
54 | // ---------------------------------------------------------------------------- |
55 | // wxLanguageInfo: encapsulates wxLanguage to OS native lang.desc. | |
56 | // translation information | |
57 | // ---------------------------------------------------------------------------- | |
58 | ||
bddd7a8d | 59 | struct WXDLLIMPEXP_BASE wxLanguageInfo |
fda91381 VS |
60 | { |
61 | int Language; // wxLanguage id | |
62 | wxString CanonicalName; // Canonical name, e.g. fr_FR | |
ea65760d | 63 | #ifdef __WXMSW__ |
dccce9ea VZ |
64 | wxUint32 WinLang, // Win32 language identifiers |
65 | WinSublang; | |
ea65760d | 66 | #endif // __WXMSW__ |
fda91381 | 67 | wxString Description; // human-readable name of the language |
978af864 | 68 | wxLayoutDirection LayoutDirection; |
ea65760d VZ |
69 | |
70 | #ifdef __WXMSW__ | |
71 | // return the LCID corresponding to this language | |
72 | wxUint32 GetLCID() const; | |
73 | #endif // __WXMSW__ | |
86d62b51 VZ |
74 | |
75 | // return the locale name corresponding to this language usable with | |
76 | // setlocale() on the current system | |
77 | wxString GetLocaleName() const; | |
fda91381 VS |
78 | }; |
79 | ||
86d62b51 VZ |
80 | // for Unix systems GetLocaleName() is trivial so implement it inline here, for |
81 | // MSW it's implemented in intl.cpp | |
82 | #ifndef __WXMSW__ | |
83 | inline wxString wxLanguageInfo::GetLocaleName() const { return CanonicalName; } | |
84 | #endif // !__WXMSW__ | |
85 | ||
18e065b4 | 86 | |
f2a139ad VZ |
87 | // ---------------------------------------------------------------------------- |
88 | // wxLocaleCategory: the category of locale settings | |
89 | // ---------------------------------------------------------------------------- | |
90 | ||
91 | enum wxLocaleCategory | |
92 | { | |
93 | // (any) numbers | |
94 | wxLOCALE_CAT_NUMBER, | |
95 | ||
96 | // date/time | |
97 | wxLOCALE_CAT_DATE, | |
98 | ||
99 | // monetary value | |
100 | wxLOCALE_CAT_MONEY, | |
101 | ||
89a7e1ff VZ |
102 | // default category for wxLocaleInfo values which only apply to a single |
103 | // category (e.g. wxLOCALE_SHORT_DATE_FMT) | |
104 | wxLOCALE_CAT_DEFAULT, | |
105 | ||
f2a139ad VZ |
106 | wxLOCALE_CAT_MAX |
107 | }; | |
108 | ||
109 | // ---------------------------------------------------------------------------- | |
110 | // wxLocaleInfo: the items understood by wxLocale::GetInfo() | |
111 | // ---------------------------------------------------------------------------- | |
112 | ||
113 | enum wxLocaleInfo | |
114 | { | |
89a7e1ff | 115 | // the thousands separator (for wxLOCALE_CAT_NUMBER or MONEY) |
f2a139ad VZ |
116 | wxLOCALE_THOUSANDS_SEP, |
117 | ||
89a7e1ff VZ |
118 | // the character used as decimal point (for wxLOCALE_CAT_NUMBER or MONEY) |
119 | wxLOCALE_DECIMAL_POINT, | |
120 | ||
121 | // the stftime()-formats used for short/long date and time representations | |
122 | // (under some platforms short and long date formats are the same) | |
123 | // | |
124 | // NB: these elements should appear in this order, code in GetInfo() relies | |
125 | // on it | |
126 | wxLOCALE_SHORT_DATE_FMT, | |
127 | wxLOCALE_LONG_DATE_FMT, | |
128 | wxLOCALE_DATE_TIME_FMT, | |
129 | wxLOCALE_TIME_FMT | |
f2a139ad VZ |
130 | |
131 | }; | |
132 | ||
c801d85f KB |
133 | // ---------------------------------------------------------------------------- |
134 | // wxLocale: encapsulates all language dependent settings, including current | |
84c18814 | 135 | // message catalogs, date, time and currency formats (TODO) &c |
c801d85f | 136 | // ---------------------------------------------------------------------------- |
fda91381 VS |
137 | |
138 | enum wxLocaleInitFlags | |
139 | { | |
f30bd8f2 | 140 | wxLOCALE_DONT_LOAD_DEFAULT = 0x0000, // don't load wxwin.mo |
3acf8a8d VS |
141 | wxLOCALE_LOAD_DEFAULT = 0x0001 // load wxwin.mo? |
142 | #if WXWIN_COMPATIBILITY_2_8 | |
143 | ,wxLOCALE_CONV_ENCODING = 0x0002 // no longer used, simply remove | |
144 | // it from the existing code | |
145 | #endif | |
fda91381 VS |
146 | }; |
147 | ||
bddd7a8d | 148 | class WXDLLIMPEXP_BASE wxLocale |
c801d85f KB |
149 | { |
150 | public: | |
84c18814 VZ |
151 | // ctor & dtor |
152 | // ----------- | |
153 | ||
154 | // call Init() if you use this ctor | |
ea8f6fc7 VZ |
155 | wxLocale() { DoCommonInit(); } |
156 | ||
84c18814 | 157 | // the ctor has a side effect of changing current locale |
31b7522e VS |
158 | wxLocale(const wxString& name, // name (for messages) |
159 | const wxString& shortName = wxEmptyString, // dir prefix (for msg files) | |
160 | const wxString& locale = wxEmptyString, // locale (for setlocale) | |
3acf8a8d VS |
161 | bool bLoadDefault = true // preload wxstd.mo? |
162 | #if WXWIN_COMPATIBILITY_2_8 | |
163 | ,bool bConvertEncoding = true // convert Win<->Unix if necessary? | |
164 | #endif | |
165 | ) | |
58d5dfc1 | 166 | { |
ea8f6fc7 VZ |
167 | DoCommonInit(); |
168 | ||
1be12624 | 169 | #if WXWIN_COMPATIBILITY_2_8 |
31b7522e | 170 | Init(name, shortName, locale, bLoadDefault, bConvertEncoding); |
1be12624 VS |
171 | #else |
172 | Init(name, shortName, locale, bLoadDefault); | |
173 | #endif | |
fda91381 VS |
174 | } |
175 | ||
ec37df57 | 176 | wxLocale(int language, // wxLanguage id or custom language |
3acf8a8d | 177 | int flags = wxLOCALE_LOAD_DEFAULT) |
ea8f6fc7 VZ |
178 | { |
179 | DoCommonInit(); | |
fda91381 | 180 | |
ea8f6fc7 VZ |
181 | Init(language, flags); |
182 | } | |
183 | ||
184 | // the same as a function (returns true on success) | |
31b7522e VS |
185 | bool Init(const wxString& name, |
186 | const wxString& shortName = wxEmptyString, | |
187 | const wxString& locale = wxEmptyString, | |
3acf8a8d VS |
188 | bool bLoadDefault = true |
189 | #if WXWIN_COMPATIBILITY_2_8 | |
190 | ,bool bConvertEncoding = true | |
191 | #endif | |
192 | ); | |
fda91381 | 193 | |
ea8f6fc7 | 194 | // same as second ctor (returns true on success) |
fda91381 | 195 | bool Init(int language = wxLANGUAGE_DEFAULT, |
3acf8a8d | 196 | int flags = wxLOCALE_LOAD_DEFAULT); |
ec37df57 | 197 | |
84c18814 | 198 | // restores old locale |
d4a724d4 | 199 | virtual ~wxLocale(); |
58d5dfc1 | 200 | |
3103e8a9 | 201 | // Try to get user's (or OS's) preferred language setting. |
ec37df57 | 202 | // Return wxLANGUAGE_UNKNOWN if language-guessing algorithm failed |
41780009 | 203 | static int GetSystemLanguage(); |
84c18814 | 204 | |
dccce9ea VZ |
205 | // get the encoding used by default for text on this system, returns |
206 | // wxFONTENCODING_SYSTEM if it couldn't be determined | |
207 | static wxFontEncoding GetSystemEncoding(); | |
208 | ||
209 | // get the string describing the system encoding, return empty string if | |
210 | // couldn't be determined | |
211 | static wxString GetSystemEncodingName(); | |
212 | ||
f2a139ad VZ |
213 | // get the values of the given locale-dependent datum: the current locale |
214 | // is used, the US default value is returned if everything else fails | |
89a7e1ff VZ |
215 | static wxString GetInfo(wxLocaleInfo index, |
216 | wxLocaleCategory cat = wxLOCALE_CAT_DEFAULT); | |
f2a139ad | 217 | |
ea8f6fc7 | 218 | // return true if the locale was set successfully |
3ca6a5f0 BP |
219 | bool IsOk() const { return m_pszOldLocale != NULL; } |
220 | ||
84c18814 | 221 | // returns locale name |
31b7522e | 222 | const wxString& GetLocale() const { return m_strLocale; } |
58d5dfc1 | 223 | |
fda91381 VS |
224 | // return current locale wxLanguage value |
225 | int GetLanguage() const { return m_language; } | |
84c18814 | 226 | |
58d5dfc1 | 227 | // return locale name to be passed to setlocale() |
fda91381 VS |
228 | wxString GetSysName() const; |
229 | ||
58d5dfc1 | 230 | // return 'canonical' name, i.e. in the form of xx[_YY], where xx is |
fda91381 VS |
231 | // language code according to ISO 639 and YY is country name |
232 | // as specified by ISO 3166. | |
233 | wxString GetCanonicalName() const { return m_strShort; } | |
58d5dfc1 | 234 | |
84c18814 VZ |
235 | // add a prefix to the catalog lookup path: the message catalog files will be |
236 | // looked up under prefix/<lang>/LC_MESSAGES, prefix/LC_MESSAGES and prefix | |
237 | // (in this order). | |
238 | // | |
239 | // This only applies to subsequent invocations of AddCatalog()! | |
18e065b4 VS |
240 | static void AddCatalogLookupPathPrefix(const wxString& prefix) |
241 | { wxFileTranslationsLoader::AddCatalogLookupPathPrefix(prefix); } | |
84c18814 VZ |
242 | |
243 | // add a catalog: it's searched for in standard places (current directory | |
244 | // first, system one after), but the you may prepend additional directories to | |
245 | // the search path with AddCatalogLookupPathPrefix(). | |
246 | // | |
247 | // The loaded catalog will be used for message lookup by GetString(). | |
248 | // | |
249 | // Returns 'true' if it was successfully loaded | |
18e065b4 VS |
250 | bool AddCatalog(const wxString& domain) |
251 | { return m_translations.AddCatalog(domain); } | |
252 | bool AddCatalog(const wxString& domain, wxLanguage msgIdLanguage) | |
253 | { return m_translations.AddCatalog(domain, msgIdLanguage); } | |
31b7522e VS |
254 | bool AddCatalog(const wxString& domain, |
255 | wxLanguage msgIdLanguage, const wxString& msgIdCharset); | |
84c18814 | 256 | |
cec5ffc4 VZ |
257 | // check if the given locale is provided by OS and C run time |
258 | static bool IsAvailable(int lang); | |
259 | ||
84c18814 | 260 | // check if the given catalog is loaded |
18e065b4 VS |
261 | bool IsLoaded(const wxString& domain) const |
262 | { return m_translations.IsLoaded(domain); } | |
58d5dfc1 | 263 | |
14f8fa9d VZ |
264 | // Retrieve the language info struct for the given language |
265 | // | |
266 | // Returns NULL if no info found, pointer must *not* be deleted by caller | |
267 | static const wxLanguageInfo *GetLanguageInfo(int lang); | |
268 | ||
4a6e4a46 VS |
269 | // Returns language name in English or empty string if the language |
270 | // is not in database | |
271 | static wxString GetLanguageName(int lang); | |
272 | ||
18e065b4 VS |
273 | // Returns ISO code ("canonical name") of language or empty string if the |
274 | // language is not in database | |
275 | static wxString GetLanguageCanonicalName(int lang); | |
276 | ||
9d1e1be4 VZ |
277 | // Find the language for the given locale string which may be either a |
278 | // canonical ISO 2 letter language code ("xx"), a language code followed by | |
279 | // the country code ("xx_XX") or a Windows full language name ("Xxxxx...") | |
280 | // | |
281 | // Returns NULL if no info found, pointer must *not* be deleted by caller | |
282 | static const wxLanguageInfo *FindLanguageInfo(const wxString& locale); | |
283 | ||
fda91381 VS |
284 | // Add custom language to the list of known languages. |
285 | // Notes: 1) wxLanguageInfo contains platform-specific data | |
286 | // 2) must be called before Init to have effect | |
41780009 | 287 | static void AddLanguage(const wxLanguageInfo& info); |
84c18814 VZ |
288 | |
289 | // retrieve the translation for a string in all loaded domains unless | |
290 | // the szDomain parameter is specified (and then only this domain is | |
291 | // searched) | |
849a28d0 | 292 | // n - additional parameter for PluralFormsParser |
84c18814 VZ |
293 | // |
294 | // return original string if translation is not available | |
295 | // (in this case an error message is generated the first time | |
296 | // a string is not found; use wxLogNull to suppress it) | |
297 | // | |
298 | // domains are searched in the last to first order, i.e. catalogs | |
299 | // added later override those added before. | |
18e065b4 VS |
300 | const wxString& GetString(const wxString& origString, |
301 | const wxString& domain = wxEmptyString) const | |
302 | { | |
303 | return m_translations.GetString(origString, domain); | |
304 | } | |
849a28d0 | 305 | // plural form version of the same: |
18e065b4 VS |
306 | const wxString& GetString(const wxString& origString, |
307 | const wxString& origString2, | |
308 | size_t n, | |
309 | const wxString& domain = wxEmptyString) const | |
310 | { | |
311 | return m_translations.GetString(origString, origString2, n, domain); | |
312 | } | |
84c18814 | 313 | |
a64be16e VS |
314 | // this is hack to work around a problem with wxGetTranslation() which |
315 | // returns const wxString& and not wxString, so when it returns untranslated | |
316 | // string, it needs to have a copy of it somewhere | |
18e065b4 VS |
317 | static const wxString& GetUntranslatedString(const wxString& str) |
318 | { return wxTranslations::GetUntranslatedString(str); } | |
a64be16e | 319 | |
84c18814 VZ |
320 | // Returns the current short name for the locale |
321 | const wxString& GetName() const { return m_strShort; } | |
322 | ||
c48908df | 323 | // return the contents of .po file header |
31b7522e | 324 | wxString GetHeaderValue(const wxString& header, |
18e065b4 VS |
325 | const wxString& domain = wxEmptyString) const |
326 | { | |
327 | return m_translations.GetHeaderValue(header, domain); | |
328 | } | |
c48908df | 329 | |
41780009 VS |
330 | // These two methods are for internal use only. First one creates |
331 | // ms_languagesDB if it doesn't already exist, second one destroys | |
332 | // it. | |
333 | static void CreateLanguagesDB(); | |
334 | static void DestroyLanguagesDB(); | |
335 | ||
84c18814 | 336 | private: |
18e065b4 VS |
337 | bool DoInit(const wxString& name, |
338 | const wxString& shortName, | |
339 | const wxString& locale); | |
58d5dfc1 | 340 | |
fda91381 | 341 | // copy default table of languages from global static array to |
41780009 VS |
342 | // m_langugagesInfo, called by InitLanguagesDB |
343 | static void InitLanguagesDB(); | |
84c18814 | 344 | |
ea8f6fc7 VZ |
345 | // initialize the member fields to default values |
346 | void DoCommonInit(); | |
347 | ||
afc94fa6 VS |
348 | wxString m_strLocale, // this locale name |
349 | m_strShort; // short name for the locale | |
fda91381 | 350 | int m_language; // this locale wxLanguage value |
84c18814 | 351 | |
52de37c7 | 352 | const char *m_pszOldLocale; // previous locale from setlocale() |
afc94fa6 | 353 | wxLocale *m_pOldLocale; // previous wxLocale |
84c18814 | 354 | |
3202d00d VS |
355 | bool m_initialized; |
356 | ||
18e065b4 VS |
357 | wxTranslations m_translations; |
358 | ||
41780009 | 359 | static wxLanguageInfoArray *ms_languagesDB; |
22f3361e | 360 | |
c0c133e1 | 361 | wxDECLARE_NO_COPY_CLASS(wxLocale); |
c801d85f KB |
362 | }; |
363 | ||
9d8046f6 | 364 | // ---------------------------------------------------------------------------- |
a1530845 | 365 | // global functions |
9d8046f6 VZ |
366 | // ---------------------------------------------------------------------------- |
367 | ||
84c18814 | 368 | // get the current locale object (note that it may be NULL!) |
bddd7a8d | 369 | extern WXDLLIMPEXP_BASE wxLocale* wxGetLocale(); |
84c18814 | 370 | |
ea144923 | 371 | #endif // wxUSE_INTL |
b12915c1 | 372 | |
dccce9ea | 373 | #endif // _WX_INTL_H_ |