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