]>
Commit | Line | Data |
---|---|---|
68bc8549 | 1 | ///////////////////////////////////////////////////////////////////////////// |
d14a1e28 RD |
2 | // Name: _intl.i |
3 | // Purpose: SWIG interface file for wxLocale and related classes | |
68bc8549 RD |
4 | // |
5 | // Author: Robin Dunn | |
6 | // | |
7 | // Created: 1-Apr-2002 | |
8 | // RCS-ID: $Id$ | |
9 | // Copyright: (c) 2002 by Total Control Software | |
10 | // Licence: wxWindows license | |
11 | ///////////////////////////////////////////////////////////////////////////// | |
12 | ||
d14a1e28 | 13 | // Not a %module |
68bc8549 RD |
14 | |
15 | ||
16 | //--------------------------------------------------------------------------- | |
68bc8549 | 17 | |
1e4a197e | 18 | %{ |
ab897a69 | 19 | #include <locale.h> |
1e4a197e RD |
20 | %} |
21 | ||
68bc8549 | 22 | //--------------------------------------------------------------------------- |
d14a1e28 | 23 | %newgroup |
68bc8549 | 24 | |
e81b607b RD |
25 | enum wxLayoutDirection |
26 | { | |
27 | wxLayout_Default, | |
28 | wxLayout_LeftToRight, | |
29 | wxLayout_RightToLeft | |
30 | }; | |
31 | ||
68bc8549 RD |
32 | |
33 | enum wxLanguage | |
34 | { | |
1e4a197e | 35 | // user's default/preffered language as got from OS: |
68bc8549 | 36 | wxLANGUAGE_DEFAULT, |
1e4a197e | 37 | // unknown language, if wxLocale::GetSystemLanguage fails: |
68bc8549 RD |
38 | wxLANGUAGE_UNKNOWN, |
39 | ||
40 | wxLANGUAGE_ABKHAZIAN, | |
41 | wxLANGUAGE_AFAR, | |
42 | wxLANGUAGE_AFRIKAANS, | |
43 | wxLANGUAGE_ALBANIAN, | |
44 | wxLANGUAGE_AMHARIC, | |
45 | wxLANGUAGE_ARABIC, | |
46 | wxLANGUAGE_ARABIC_ALGERIA, | |
47 | wxLANGUAGE_ARABIC_BAHRAIN, | |
48 | wxLANGUAGE_ARABIC_EGYPT, | |
49 | wxLANGUAGE_ARABIC_IRAQ, | |
50 | wxLANGUAGE_ARABIC_JORDAN, | |
51 | wxLANGUAGE_ARABIC_KUWAIT, | |
52 | wxLANGUAGE_ARABIC_LEBANON, | |
53 | wxLANGUAGE_ARABIC_LIBYA, | |
54 | wxLANGUAGE_ARABIC_MOROCCO, | |
55 | wxLANGUAGE_ARABIC_OMAN, | |
56 | wxLANGUAGE_ARABIC_QATAR, | |
57 | wxLANGUAGE_ARABIC_SAUDI_ARABIA, | |
58 | wxLANGUAGE_ARABIC_SUDAN, | |
59 | wxLANGUAGE_ARABIC_SYRIA, | |
60 | wxLANGUAGE_ARABIC_TUNISIA, | |
61 | wxLANGUAGE_ARABIC_UAE, | |
62 | wxLANGUAGE_ARABIC_YEMEN, | |
63 | wxLANGUAGE_ARMENIAN, | |
64 | wxLANGUAGE_ASSAMESE, | |
65 | wxLANGUAGE_AYMARA, | |
66 | wxLANGUAGE_AZERI, | |
67 | wxLANGUAGE_AZERI_CYRILLIC, | |
68 | wxLANGUAGE_AZERI_LATIN, | |
69 | wxLANGUAGE_BASHKIR, | |
70 | wxLANGUAGE_BASQUE, | |
71 | wxLANGUAGE_BELARUSIAN, | |
72 | wxLANGUAGE_BENGALI, | |
73 | wxLANGUAGE_BHUTANI, | |
74 | wxLANGUAGE_BIHARI, | |
75 | wxLANGUAGE_BISLAMA, | |
76 | wxLANGUAGE_BRETON, | |
77 | wxLANGUAGE_BULGARIAN, | |
78 | wxLANGUAGE_BURMESE, | |
79 | wxLANGUAGE_CAMBODIAN, | |
80 | wxLANGUAGE_CATALAN, | |
81 | wxLANGUAGE_CHINESE, | |
82 | wxLANGUAGE_CHINESE_SIMPLIFIED, | |
83 | wxLANGUAGE_CHINESE_TRADITIONAL, | |
84 | wxLANGUAGE_CHINESE_HONGKONG, | |
85 | wxLANGUAGE_CHINESE_MACAU, | |
86 | wxLANGUAGE_CHINESE_SINGAPORE, | |
87 | wxLANGUAGE_CHINESE_TAIWAN, | |
88 | wxLANGUAGE_CORSICAN, | |
89 | wxLANGUAGE_CROATIAN, | |
90 | wxLANGUAGE_CZECH, | |
91 | wxLANGUAGE_DANISH, | |
92 | wxLANGUAGE_DUTCH, | |
93 | wxLANGUAGE_DUTCH_BELGIAN, | |
94 | wxLANGUAGE_ENGLISH, | |
95 | wxLANGUAGE_ENGLISH_UK, | |
96 | wxLANGUAGE_ENGLISH_US, | |
97 | wxLANGUAGE_ENGLISH_AUSTRALIA, | |
98 | wxLANGUAGE_ENGLISH_BELIZE, | |
99 | wxLANGUAGE_ENGLISH_BOTSWANA, | |
100 | wxLANGUAGE_ENGLISH_CANADA, | |
101 | wxLANGUAGE_ENGLISH_CARIBBEAN, | |
102 | wxLANGUAGE_ENGLISH_DENMARK, | |
103 | wxLANGUAGE_ENGLISH_EIRE, | |
104 | wxLANGUAGE_ENGLISH_JAMAICA, | |
105 | wxLANGUAGE_ENGLISH_NEW_ZEALAND, | |
106 | wxLANGUAGE_ENGLISH_PHILIPPINES, | |
107 | wxLANGUAGE_ENGLISH_SOUTH_AFRICA, | |
108 | wxLANGUAGE_ENGLISH_TRINIDAD, | |
109 | wxLANGUAGE_ENGLISH_ZIMBABWE, | |
110 | wxLANGUAGE_ESPERANTO, | |
111 | wxLANGUAGE_ESTONIAN, | |
112 | wxLANGUAGE_FAEROESE, | |
113 | wxLANGUAGE_FARSI, | |
114 | wxLANGUAGE_FIJI, | |
115 | wxLANGUAGE_FINNISH, | |
116 | wxLANGUAGE_FRENCH, | |
117 | wxLANGUAGE_FRENCH_BELGIAN, | |
118 | wxLANGUAGE_FRENCH_CANADIAN, | |
119 | wxLANGUAGE_FRENCH_LUXEMBOURG, | |
120 | wxLANGUAGE_FRENCH_MONACO, | |
121 | wxLANGUAGE_FRENCH_SWISS, | |
122 | wxLANGUAGE_FRISIAN, | |
123 | wxLANGUAGE_GALICIAN, | |
124 | wxLANGUAGE_GEORGIAN, | |
125 | wxLANGUAGE_GERMAN, | |
126 | wxLANGUAGE_GERMAN_AUSTRIAN, | |
127 | wxLANGUAGE_GERMAN_BELGIUM, | |
128 | wxLANGUAGE_GERMAN_LIECHTENSTEIN, | |
129 | wxLANGUAGE_GERMAN_LUXEMBOURG, | |
130 | wxLANGUAGE_GERMAN_SWISS, | |
131 | wxLANGUAGE_GREEK, | |
132 | wxLANGUAGE_GREENLANDIC, | |
133 | wxLANGUAGE_GUARANI, | |
134 | wxLANGUAGE_GUJARATI, | |
135 | wxLANGUAGE_HAUSA, | |
136 | wxLANGUAGE_HEBREW, | |
137 | wxLANGUAGE_HINDI, | |
138 | wxLANGUAGE_HUNGARIAN, | |
139 | wxLANGUAGE_ICELANDIC, | |
140 | wxLANGUAGE_INDONESIAN, | |
141 | wxLANGUAGE_INTERLINGUA, | |
142 | wxLANGUAGE_INTERLINGUE, | |
143 | wxLANGUAGE_INUKTITUT, | |
144 | wxLANGUAGE_INUPIAK, | |
145 | wxLANGUAGE_IRISH, | |
146 | wxLANGUAGE_ITALIAN, | |
147 | wxLANGUAGE_ITALIAN_SWISS, | |
148 | wxLANGUAGE_JAPANESE, | |
149 | wxLANGUAGE_JAVANESE, | |
150 | wxLANGUAGE_KANNADA, | |
151 | wxLANGUAGE_KASHMIRI, | |
152 | wxLANGUAGE_KASHMIRI_INDIA, | |
153 | wxLANGUAGE_KAZAKH, | |
154 | wxLANGUAGE_KERNEWEK, | |
155 | wxLANGUAGE_KINYARWANDA, | |
156 | wxLANGUAGE_KIRGHIZ, | |
157 | wxLANGUAGE_KIRUNDI, | |
158 | wxLANGUAGE_KONKANI, | |
159 | wxLANGUAGE_KOREAN, | |
160 | wxLANGUAGE_KURDISH, | |
161 | wxLANGUAGE_LAOTHIAN, | |
162 | wxLANGUAGE_LATIN, | |
163 | wxLANGUAGE_LATVIAN, | |
164 | wxLANGUAGE_LINGALA, | |
165 | wxLANGUAGE_LITHUANIAN, | |
166 | wxLANGUAGE_MACEDONIAN, | |
167 | wxLANGUAGE_MALAGASY, | |
168 | wxLANGUAGE_MALAY, | |
169 | wxLANGUAGE_MALAYALAM, | |
170 | wxLANGUAGE_MALAY_BRUNEI_DARUSSALAM, | |
171 | wxLANGUAGE_MALAY_MALAYSIA, | |
172 | wxLANGUAGE_MALTESE, | |
173 | wxLANGUAGE_MANIPURI, | |
174 | wxLANGUAGE_MAORI, | |
175 | wxLANGUAGE_MARATHI, | |
176 | wxLANGUAGE_MOLDAVIAN, | |
177 | wxLANGUAGE_MONGOLIAN, | |
178 | wxLANGUAGE_NAURU, | |
179 | wxLANGUAGE_NEPALI, | |
180 | wxLANGUAGE_NEPALI_INDIA, | |
181 | wxLANGUAGE_NORWEGIAN_BOKMAL, | |
182 | wxLANGUAGE_NORWEGIAN_NYNORSK, | |
183 | wxLANGUAGE_OCCITAN, | |
184 | wxLANGUAGE_ORIYA, | |
185 | wxLANGUAGE_OROMO, | |
186 | wxLANGUAGE_PASHTO, | |
187 | wxLANGUAGE_POLISH, | |
188 | wxLANGUAGE_PORTUGUESE, | |
189 | wxLANGUAGE_PORTUGUESE_BRAZILIAN, | |
190 | wxLANGUAGE_PUNJABI, | |
191 | wxLANGUAGE_QUECHUA, | |
192 | wxLANGUAGE_RHAETO_ROMANCE, | |
193 | wxLANGUAGE_ROMANIAN, | |
194 | wxLANGUAGE_RUSSIAN, | |
195 | wxLANGUAGE_RUSSIAN_UKRAINE, | |
196 | wxLANGUAGE_SAMOAN, | |
197 | wxLANGUAGE_SANGHO, | |
198 | wxLANGUAGE_SANSKRIT, | |
199 | wxLANGUAGE_SCOTS_GAELIC, | |
200 | wxLANGUAGE_SERBIAN, | |
201 | wxLANGUAGE_SERBIAN_CYRILLIC, | |
202 | wxLANGUAGE_SERBIAN_LATIN, | |
203 | wxLANGUAGE_SERBO_CROATIAN, | |
204 | wxLANGUAGE_SESOTHO, | |
205 | wxLANGUAGE_SETSWANA, | |
206 | wxLANGUAGE_SHONA, | |
207 | wxLANGUAGE_SINDHI, | |
208 | wxLANGUAGE_SINHALESE, | |
209 | wxLANGUAGE_SISWATI, | |
210 | wxLANGUAGE_SLOVAK, | |
211 | wxLANGUAGE_SLOVENIAN, | |
212 | wxLANGUAGE_SOMALI, | |
213 | wxLANGUAGE_SPANISH, | |
214 | wxLANGUAGE_SPANISH_ARGENTINA, | |
215 | wxLANGUAGE_SPANISH_BOLIVIA, | |
216 | wxLANGUAGE_SPANISH_CHILE, | |
217 | wxLANGUAGE_SPANISH_COLOMBIA, | |
218 | wxLANGUAGE_SPANISH_COSTA_RICA, | |
219 | wxLANGUAGE_SPANISH_DOMINICAN_REPUBLIC, | |
220 | wxLANGUAGE_SPANISH_ECUADOR, | |
221 | wxLANGUAGE_SPANISH_EL_SALVADOR, | |
222 | wxLANGUAGE_SPANISH_GUATEMALA, | |
223 | wxLANGUAGE_SPANISH_HONDURAS, | |
224 | wxLANGUAGE_SPANISH_MEXICAN, | |
225 | wxLANGUAGE_SPANISH_MODERN, | |
226 | wxLANGUAGE_SPANISH_NICARAGUA, | |
227 | wxLANGUAGE_SPANISH_PANAMA, | |
228 | wxLANGUAGE_SPANISH_PARAGUAY, | |
229 | wxLANGUAGE_SPANISH_PERU, | |
230 | wxLANGUAGE_SPANISH_PUERTO_RICO, | |
231 | wxLANGUAGE_SPANISH_URUGUAY, | |
232 | wxLANGUAGE_SPANISH_US, | |
233 | wxLANGUAGE_SPANISH_VENEZUELA, | |
234 | wxLANGUAGE_SUNDANESE, | |
235 | wxLANGUAGE_SWAHILI, | |
236 | wxLANGUAGE_SWEDISH, | |
237 | wxLANGUAGE_SWEDISH_FINLAND, | |
238 | wxLANGUAGE_TAGALOG, | |
239 | wxLANGUAGE_TAJIK, | |
240 | wxLANGUAGE_TAMIL, | |
241 | wxLANGUAGE_TATAR, | |
242 | wxLANGUAGE_TELUGU, | |
243 | wxLANGUAGE_THAI, | |
244 | wxLANGUAGE_TIBETAN, | |
245 | wxLANGUAGE_TIGRINYA, | |
246 | wxLANGUAGE_TONGA, | |
247 | wxLANGUAGE_TSONGA, | |
248 | wxLANGUAGE_TURKISH, | |
249 | wxLANGUAGE_TURKMEN, | |
250 | wxLANGUAGE_TWI, | |
251 | wxLANGUAGE_UIGHUR, | |
252 | wxLANGUAGE_UKRAINIAN, | |
253 | wxLANGUAGE_URDU, | |
254 | wxLANGUAGE_URDU_INDIA, | |
255 | wxLANGUAGE_URDU_PAKISTAN, | |
256 | wxLANGUAGE_UZBEK, | |
257 | wxLANGUAGE_UZBEK_CYRILLIC, | |
258 | wxLANGUAGE_UZBEK_LATIN, | |
259 | wxLANGUAGE_VIETNAMESE, | |
260 | wxLANGUAGE_VOLAPUK, | |
261 | wxLANGUAGE_WELSH, | |
262 | wxLANGUAGE_WOLOF, | |
263 | wxLANGUAGE_XHOSA, | |
264 | wxLANGUAGE_YIDDISH, | |
265 | wxLANGUAGE_YORUBA, | |
266 | wxLANGUAGE_ZHUANG, | |
267 | wxLANGUAGE_ZULU, | |
268 | ||
269 | // for custom, user-defined languages: | |
270 | wxLANGUAGE_USER_DEFINED | |
271 | }; | |
272 | ||
d14a1e28 RD |
273 | |
274 | //--------------------------------------------------------------------------- | |
275 | ||
276 | ||
68bc8549 RD |
277 | // wxLanguageInfo: encapsulates wxLanguage to OS native lang.desc. |
278 | // translation information | |
d14a1e28 | 279 | struct wxLanguageInfo |
68bc8549 | 280 | { |
68bc8549 RD |
281 | int Language; // wxLanguage id |
282 | wxString CanonicalName; // Canonical name, e.g. fr_FR | |
283 | wxString Description; // human-readable name of the language | |
284 | }; | |
285 | ||
286 | // wxLocaleCategory: the category of locale settings | |
287 | enum wxLocaleCategory | |
288 | { | |
289 | wxLOCALE_CAT_NUMBER, | |
290 | wxLOCALE_CAT_DATE, | |
291 | wxLOCALE_CAT_MONEY, | |
292 | wxLOCALE_CAT_MAX | |
293 | }; | |
294 | ||
295 | // wxLocaleInfo: the items understood by wxLocale::GetInfo() | |
296 | enum wxLocaleInfo | |
297 | { | |
298 | wxLOCALE_THOUSANDS_SEP, | |
299 | wxLOCALE_DECIMAL_POINT | |
300 | ||
301 | }; | |
302 | ||
303 | // wxLocale: encapsulates all language dependent settings, including current | |
304 | // message catalogs, date, time and currency formats (TODO) &c | |
305 | enum wxLocaleInitFlags | |
306 | { | |
307 | wxLOCALE_LOAD_DEFAULT = 0x0001, // load wxwin.mo? | |
308 | wxLOCALE_CONV_ENCODING = 0x0002 // convert encoding on the fly? | |
309 | }; | |
310 | ||
d14a1e28 RD |
311 | |
312 | //--------------------------------------------------------------------------- | |
313 | ||
68bc8549 RD |
314 | class wxLocale |
315 | { | |
316 | public: | |
317 | // ctor & dtor | |
318 | // ----------- | |
2693507f RD |
319 | %extend { |
320 | wxLocale(int language = -1, | |
321 | int flags = wxLOCALE_LOAD_DEFAULT | wxLOCALE_CONV_ENCODING) { | |
ab897a69 | 322 | wxLocale* loc; |
2693507f | 323 | if (language == -1) |
ab897a69 | 324 | loc = new wxLocale(); |
2693507f | 325 | else |
ab897a69 RD |
326 | loc = new wxLocale(language, flags); |
327 | // Python before 2.4 needs to have LC_NUMERIC set to "C" in order | |
328 | // for the floating point conversions and such to work right. | |
329 | %#if PY_VERSION_HEX < 0x02040000 | |
330 | setlocale(LC_NUMERIC, "C"); | |
331 | %#endif | |
332 | return loc; | |
2693507f RD |
333 | } |
334 | } | |
68bc8549 | 335 | |
68bc8549 RD |
336 | // restores old locale |
337 | ~wxLocale(); | |
338 | ||
ab897a69 RD |
339 | %extend { |
340 | bool Init1(const wxString& szName, | |
341 | const wxString& szShort = wxPyEmptyString, | |
342 | const wxString& szLocale = wxPyEmptyString, | |
343 | bool bLoadDefault = true, | |
344 | bool bConvertEncoding = false) { | |
345 | bool rc = self->Init(szName, szShort, szLocale, bLoadDefault, bConvertEncoding); | |
346 | // Python before 2.4 needs to have LC_NUMERIC set to "C" in order | |
347 | // for the floating point conversions and such to work right. | |
348 | %#if PY_VERSION_HEX < 0x02040000 | |
349 | setlocale(LC_NUMERIC, "C"); | |
350 | %#endif | |
351 | return rc; | |
352 | } | |
353 | ||
354 | bool Init2(int language = wxLANGUAGE_DEFAULT, | |
355 | int flags = wxLOCALE_LOAD_DEFAULT | wxLOCALE_CONV_ENCODING) { | |
356 | bool rc = self->Init(language, flags); | |
357 | // Python before 2.4 needs to have LC_NUMERIC set to "C" in order | |
358 | // for the floating point conversions and such to work right. | |
359 | %#if PY_VERSION_HEX < 0x02040000 | |
360 | setlocale(LC_NUMERIC, "C"); | |
361 | %#endif | |
362 | return rc; | |
363 | } | |
364 | } | |
1e4a197e | 365 | |
ab897a69 | 366 | |
1e4a197e | 367 | |
d14a1e28 | 368 | %pythoncode { |
1e4a197e RD |
369 | def Init(self, *_args, **_kwargs): |
370 | if type(_args[0]) in [type(''), type(u'')]: | |
1fded56b | 371 | val = self.Init1(*_args, **_kwargs) |
1e4a197e | 372 | else: |
1fded56b | 373 | val = self.Init2(*_args, **_kwargs) |
1e4a197e | 374 | return val |
d14a1e28 | 375 | } |
1e4a197e | 376 | |
68bc8549 RD |
377 | // Try to get user's (or OS's) prefered language setting. |
378 | // Return wxLANGUAGE_UNKNOWN if language-guessing algorithm failed | |
379 | static int GetSystemLanguage(); | |
380 | ||
381 | // get the encoding used by default for text on this system, returns | |
382 | // wxFONTENCODING_SYSTEM if it couldn't be determined | |
383 | static wxFontEncoding GetSystemEncoding(); | |
384 | ||
385 | // get the string describing the system encoding, return empty string if | |
386 | // couldn't be determined | |
387 | static wxString GetSystemEncodingName(); | |
388 | ||
389 | ||
390 | // THIS ONE IS COMMENTED OUT IN src/common/intl.cpp | |
391 | // get the values of the given locale-dependent datum: the current locale | |
392 | // is used, the US default value is returned if everything else fails | |
393 | // static wxString GetInfo(wxLocaleInfo index, wxLocaleCategory cat); | |
394 | ||
dd9f7fea | 395 | // return True if the locale was set successfully |
68bc8549 | 396 | bool IsOk() const; |
d14a1e28 | 397 | %pythoncode { def __nonzero__(self): return self.IsOk() }; |
68bc8549 RD |
398 | |
399 | // returns locale name | |
400 | wxString GetLocale() const; | |
401 | ||
402 | // return current locale wxLanguage value | |
403 | int GetLanguage() const; | |
404 | ||
405 | // return locale name to be passed to setlocale() | |
406 | wxString GetSysName() const; | |
407 | ||
408 | // return 'canonical' name, i.e. in the form of xx[_YY], where xx is | |
409 | // language code according to ISO 639 and YY is country name | |
410 | // as specified by ISO 3166. | |
411 | wxString GetCanonicalName() const; | |
412 | ||
413 | // add a prefix to the catalog lookup path: the message catalog files will be | |
414 | // looked up under prefix/<lang>/LC_MESSAGES, prefix/LC_MESSAGES and prefix | |
415 | // (in this order). | |
416 | // | |
417 | // This only applies to subsequent invocations of AddCatalog()! | |
418 | static void AddCatalogLookupPathPrefix(const wxString& prefix); | |
419 | ||
420 | // add a catalog: it's searched for in standard places (current directory | |
421 | // first, system one after), but the you may prepend additional directories to | |
422 | // the search path with AddCatalogLookupPathPrefix(). | |
423 | // | |
424 | // The loaded catalog will be used for message lookup by GetString(). | |
425 | // | |
dd9f7fea | 426 | // Returns 'True' if it was successfully loaded |
68bc8549 RD |
427 | bool AddCatalog(const wxString& szDomain); |
428 | ||
429 | // check if the given catalog is loaded | |
430 | bool IsLoaded(const wxString& szDomain) const; | |
431 | ||
923e5f56 RD |
432 | // Retrieve the language info struct for the given language |
433 | // | |
434 | // Returns NULL if no info found, pointer must *not* be deleted by caller | |
435 | static const wxLanguageInfo *GetLanguageInfo(int lang); | |
436 | ||
3ef86e32 RD |
437 | // Returns language name in English or empty string if the language |
438 | // is not in database | |
439 | static wxString GetLanguageName(int lang); | |
440 | ||
9cbf6f6e RD |
441 | // Find the language for the given locale string which may be either a |
442 | // canonical ISO 2 letter language code ("xx"), a language code followed by | |
443 | // the country code ("xx_XX") or a Windows full language name ("Xxxxx...") | |
444 | // | |
445 | // Returns NULL if no info found, pointer must *not* be deleted by caller | |
446 | static const wxLanguageInfo *FindLanguageInfo(const wxString& locale); | |
447 | ||
6789bce9 | 448 | // Add custom language to the list of known languages. |
68bc8549 RD |
449 | // Notes: 1) wxLanguageInfo contains platform-specific data |
450 | // 2) must be called before Init to have effect | |
451 | static void AddLanguage(const wxLanguageInfo& info); | |
452 | ||
453 | // retrieve the translation for a string in all loaded domains unless | |
454 | // the szDomain parameter is specified (and then only this domain is | |
455 | // searched) | |
456 | // | |
457 | // return original string if translation is not available | |
458 | // (in this case an error message is generated the first time | |
459 | // a string is not found; use wxLogNull to suppress it) | |
460 | // | |
461 | // domains are searched in the last to first order, i.e. catalogs | |
462 | // added later override those added before. | |
463 | wxString GetString(const wxString& szOrigString, | |
464 | const wxString& szDomain = wxPyEmptyString) const; | |
465 | ||
466 | // Returns the current short name for the locale | |
467 | const wxString& GetName() const; | |
468 | ||
76b8fa1d RD |
469 | |
470 | %property(CanonicalName, GetCanonicalName, doc="See `GetCanonicalName`"); | |
471 | %property(Language, GetLanguage, doc="See `GetLanguage`"); | |
472 | %property(Locale, GetLocale, doc="See `GetLocale`"); | |
473 | %property(Name, GetName, doc="See `GetName`"); | |
474 | %property(String, GetString, doc="See `GetString`"); | |
475 | %property(SysName, GetSysName, doc="See `GetSysName`"); | |
68bc8549 RD |
476 | }; |
477 | ||
d4a724d4 RD |
478 | //--------------------------------------------------------------------------- |
479 | ||
480 | %{ | |
481 | class wxPyLocale : public wxLocale | |
482 | { | |
483 | public: | |
484 | wxPyLocale(); | |
485 | ||
486 | wxPyLocale(const wxChar *szName, // name (for messages) | |
487 | const wxChar *szShort = (const wxChar *) NULL, // dir prefix (for msg files) | |
488 | const wxChar *szLocale = (const wxChar *) NULL, // locale (for setlocale) | |
489 | bool bLoadDefault = true, // preload wxstd.mo? | |
490 | bool bConvertEncoding = false); // convert Win<->Unix if necessary? | |
491 | ||
492 | wxPyLocale(int language, // wxLanguage id or custom language | |
493 | int flags = wxLOCALE_LOAD_DEFAULT | wxLOCALE_CONV_ENCODING); | |
494 | ||
495 | ~wxPyLocale(); | |
496 | ||
497 | virtual const wxChar *GetString(const wxChar *szOrigString, | |
498 | const wxChar *szDomain = NULL) const; | |
499 | virtual const wxChar *GetString(const wxChar *szOrigString, | |
500 | const wxChar *szOrigString2, size_t n, | |
501 | const wxChar *szDomain = NULL) const; | |
502 | ||
503 | virtual wxChar *GetSingularString(const wxChar *szOrigString, | |
504 | const wxChar *szDomain = NULL) const; | |
505 | virtual wxChar *GetPluralString(const wxChar *szOrigString, | |
506 | const wxChar *szOrigString2, size_t n, | |
507 | const wxChar *szDomain = NULL) const; | |
508 | ||
509 | PYPRIVATE; | |
510 | private: | |
511 | DECLARE_NO_COPY_CLASS(wxPyLocale) | |
512 | }; | |
513 | ||
514 | wxPyLocale::wxPyLocale() : wxLocale() | |
515 | { | |
516 | } | |
517 | ||
518 | wxPyLocale::wxPyLocale(const wxChar *szName, // name (for messages) | |
519 | const wxChar *szShort, // dir prefix (for msg files) | |
520 | const wxChar *szLocale, // locale (for setlocale) | |
521 | bool bLoadDefault, // preload wxstd.mo? | |
522 | bool bConvertEncoding) // convert Win<->Unix if necessary? | |
523 | : wxLocale(szName, szShort, szLocale, bLoadDefault, bConvertEncoding) | |
524 | { | |
525 | } | |
526 | ||
527 | wxPyLocale::wxPyLocale(int language, // wxLanguage id or custom language | |
528 | int flags) : wxLocale(language, flags) | |
529 | { | |
530 | } | |
531 | ||
532 | wxPyLocale::~wxPyLocale() | |
533 | { | |
534 | } | |
68bc8549 | 535 | |
d4a724d4 RD |
536 | const wxChar *wxPyLocale::GetString(const wxChar *szOrigString, |
537 | const wxChar *szDomain) const | |
538 | { | |
539 | wxChar *str = GetSingularString(szOrigString, szDomain); | |
540 | return (str != NULL) ? str : wxLocale::GetString(szOrigString, szDomain); | |
541 | } | |
542 | ||
543 | const wxChar *wxPyLocale::GetString(const wxChar *szOrigString, | |
544 | const wxChar *szOrigString2, size_t n, | |
545 | const wxChar *szDomain) const | |
546 | { | |
547 | wxChar *str = GetPluralString(szOrigString, szOrigString2, n, szDomain); | |
548 | return (str != NULL) ? str : wxLocale::GetString(szOrigString, szOrigString2, n, szDomain); | |
549 | } | |
550 | ||
551 | wxChar *wxPyLocale::GetSingularString(const wxChar *szOrigString, | |
552 | const wxChar *szDomain) const | |
553 | { | |
554 | bool found; | |
555 | static wxString str; | |
556 | str = _T("error in translation"); // when the first if condition is true but the second if condition is not we do not want to return the previously queried string. | |
557 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); | |
558 | if((found=wxPyCBH_findCallback(m_myInst, "GetSingularString"))) { | |
559 | PyObject* param1 = wx2PyString(szOrigString); | |
560 | PyObject* param2 = wx2PyString(szDomain); | |
561 | PyObject* ret = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(OO)", param1, param2)); | |
562 | Py_DECREF(param1); | |
563 | Py_DECREF(param2); | |
564 | if (ret) { | |
565 | str = Py2wxString(ret); | |
566 | Py_DECREF(ret); | |
567 | } | |
568 | } | |
569 | wxPyEndBlockThreads(blocked); | |
570 | return (found ? (wxChar*)str.c_str() : NULL); | |
571 | } | |
572 | ||
573 | wxChar *wxPyLocale::GetPluralString(const wxChar *szOrigString, | |
574 | const wxChar *szOrigString2, size_t n, | |
575 | const wxChar *szDomain) const | |
576 | { | |
577 | bool found; | |
578 | static wxString str; | |
579 | str = _T("error in translation"); // when the first if condition is true but the second if condition is not we do not want to return the previously queried string. | |
580 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); | |
581 | if((found=wxPyCBH_findCallback(m_myInst, "GetPluralString"))) { | |
582 | PyObject* param1 = wx2PyString(szOrigString); | |
583 | PyObject* param2 = wx2PyString(szOrigString2); | |
584 | PyObject* param4 = wx2PyString(szDomain); | |
585 | PyObject* ret = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(OOiO)", param1, param2, (int)n, param4)); | |
586 | Py_DECREF(param1); | |
587 | Py_DECREF(param2); | |
588 | Py_DECREF(param4); | |
589 | if( ret) { | |
590 | str = Py2wxString(ret); | |
591 | Py_DECREF(ret); | |
592 | } | |
593 | } | |
594 | wxPyEndBlockThreads(blocked); | |
595 | return (found ? (wxChar*)str.c_str() : NULL); | |
596 | } | |
597 | %} | |
598 | ||
599 | ||
600 | class wxPyLocale : public wxLocale | |
601 | { | |
602 | public: | |
603 | %pythonAppend wxPyLocale "self._setCallbackInfo(self, PyLocale)" | |
604 | ||
605 | // ctor & dtor | |
606 | // ----------- | |
607 | %extend { | |
608 | wxPyLocale(int language = -1, | |
609 | int flags = wxLOCALE_LOAD_DEFAULT | wxLOCALE_CONV_ENCODING) { | |
610 | wxPyLocale* loc; | |
611 | if (language == -1) | |
612 | loc = new wxPyLocale(); | |
613 | else | |
614 | loc = new wxPyLocale(language, flags); | |
615 | // Python before 2.4 needs to have LC_NUMERIC set to "C" in order | |
616 | // for the floating point conversions and such to work right. | |
617 | %#if PY_VERSION_HEX < 0x02040000 | |
618 | setlocale(LC_NUMERIC, "C"); | |
619 | %#endif | |
620 | return loc; | |
621 | } | |
622 | } | |
623 | ~wxPyLocale(); | |
624 | ||
625 | void _setCallbackInfo(PyObject* self, PyObject* _class); | |
626 | ||
627 | virtual const wxChar *GetSingularString(const wxChar *szOrigString, | |
628 | const wxChar *szDomain = NULL) const; | |
629 | virtual const wxChar *GetPluralString(const wxChar *szOrigString, | |
630 | const wxChar *szOrigString2, size_t n, | |
631 | const wxChar *szDomain = NULL) const; | |
632 | }; | |
633 | ||
634 | //--------------------------------------------------------------------------- | |
68bc8549 RD |
635 | |
636 | // get the current locale object (note that it may be NULL!) | |
637 | wxLocale* wxGetLocale(); | |
638 | ||
639 | // get the translation of the string in the current locale | |
d14a1e28 | 640 | %nokwargs wxGetTranslation; |
83486d3b | 641 | wxString wxGetTranslation(const wxString& str); |
d4a724d4 | 642 | wxString wxGetTranslation(const wxString& str, const wxString& domain); |
83486d3b | 643 | wxString wxGetTranslation(const wxString& str, const wxString& strPlural, size_t n); |
d4a724d4 | 644 | wxString wxGetTranslation(const wxString& str, const wxString& strPlural, size_t n, const wxString& domain); |
d14a1e28 RD |
645 | |
646 | //--------------------------------------------------------------------------- | |
647 | %newgroup | |
68bc8549 RD |
648 | |
649 | ||
68bc8549 RD |
650 | // wxEncodingConverter |
651 | // This class is capable of converting strings between any two | |
652 | // 8bit encodings/charsets. It can also convert from/to Unicode | |
653 | ||
654 | ||
d14a1e28 RD |
655 | %typemap(out) wxFontEncodingArray { |
656 | $result = PyList_New(0); | |
657 | for (size_t i=0; i < $1.GetCount(); i++) { | |
658 | PyObject* number = PyInt_FromLong($1.Item(i)); | |
659 | PyList_Append($result, number); | |
68bc8549 RD |
660 | Py_DECREF(number); |
661 | } | |
662 | } | |
663 | ||
664 | ||
665 | enum | |
666 | { | |
667 | wxCONVERT_STRICT, | |
668 | wxCONVERT_SUBSTITUTE | |
669 | }; | |
670 | ||
671 | ||
672 | enum | |
673 | { | |
674 | wxPLATFORM_CURRENT = -1, | |
675 | ||
676 | wxPLATFORM_UNIX = 0, | |
677 | wxPLATFORM_WINDOWS, | |
678 | wxPLATFORM_OS2, | |
679 | wxPLATFORM_MAC | |
680 | }; | |
681 | ||
682 | ||
683 | class wxEncodingConverter : public wxObject | |
684 | { | |
685 | public: | |
686 | ||
687 | wxEncodingConverter(); | |
688 | ~wxEncodingConverter(); | |
689 | ||
690 | ||
691 | // Initialize convertion. Both output or input encoding may | |
692 | // be wxFONTENCODING_UNICODE, but only if wxUSE_WCHAR_T is set to 1. | |
693 | // | |
694 | // All subsequent calls to Convert() will interpret it's argument | |
695 | // as a string in input_enc encoding and will output string in | |
696 | // output_enc encoding. | |
697 | // | |
698 | // You must call this method before calling Convert. You may call | |
699 | // it more than once in order to switch to another conversion | |
700 | // | |
701 | // Method affects behaviour of Convert() in case input character | |
702 | // cannot be converted because it does not exist in output encoding: | |
703 | // wxCONVERT_STRICT -- | |
704 | // follow behaviour of GNU Recode - just copy unconvertable | |
705 | // characters to output and don't change them (it's integer | |
706 | // value will stay the same) | |
707 | // wxCONVERT_SUBSTITUTE -- | |
708 | // try some (lossy) substitutions - e.g. replace | |
709 | // unconvertable latin capitals with acute by ordinary | |
710 | // capitals, replace en-dash or em-dash by '-' etc. | |
711 | // both modes gurantee that output string will have same length | |
712 | // as input string | |
713 | // | |
dd9f7fea | 714 | // Returns False if given conversion is impossible, True otherwise |
68bc8549 RD |
715 | // (conversion may be impossible either if you try to convert |
716 | // to Unicode with non-Unicode build of wxWindows or if input | |
717 | // or output encoding is not supported.) | |
718 | bool Init(wxFontEncoding input_enc, wxFontEncoding output_enc, int method = wxCONVERT_STRICT); | |
719 | ||
f60765b0 RD |
720 | |
721 | // TODO: Need to do something about unicode mode... | |
722 | ||
68bc8549 RD |
723 | // Convert input string according to settings passed to Init. |
724 | // Note that you must call Init before using Convert! | |
725 | wxString Convert(const wxString& input); | |
726 | ||
727 | // void Convert(const char* input, char* output); | |
728 | ||
729 | // #if wxUSE_WCHAR_T | |
730 | // void Convert(const char* input, wchar_t* output); | |
731 | // void Convert(const wchar_t* input, char* output); | |
732 | // void Convert(const wchar_t* input, wchar_t* output); | |
733 | // void Convert(wchar_t* str) { Convert(str, str); } | |
734 | // #endif | |
735 | ||
736 | ||
f60765b0 | 737 | |
68bc8549 RD |
738 | // Return equivalent(s) for given font that are used |
739 | // under given platform. wxPLATFORM_CURRENT means the plaform | |
740 | // this binary was compiled for | |
741 | // | |
742 | // Examples: | |
743 | // current platform enc returned value | |
744 | // ----------------------------------------------------- | |
745 | // unix CP1250 {ISO8859_2} | |
746 | // unix ISO8859_2 {} | |
747 | // windows ISO8859_2 {CP1250} | |
748 | // | |
749 | // Equivalence is defined in terms of convertibility: | |
750 | // 2 encodings are equivalent if you can convert text between | |
751 | // then without loosing information (it may - and will - happen | |
752 | // that you loose special chars like quotation marks or em-dashes | |
753 | // but you shouldn't loose any diacritics and language-specific | |
754 | // characters when converting between equivalent encodings). | |
755 | // | |
756 | // Convert() method is not limited to converting between | |
757 | // equivalent encodings, it can convert between arbitrary | |
758 | // two encodings! | |
759 | // | |
760 | // Remember that this function does _NOT_ check for presence of | |
761 | // fonts in system. It only tells you what are most suitable | |
762 | // encodings. (It usually returns only one encoding) | |
763 | // | |
764 | // Note that argument enc itself may be present in returned array! | |
765 | // (so that you can -- as a side effect -- detect whether the | |
766 | // encoding is native for this platform or not) | |
767 | static wxFontEncodingArray GetPlatformEquivalents(wxFontEncoding enc, | |
768 | int platform = wxPLATFORM_CURRENT); | |
769 | ||
770 | // Similar to GetPlatformEquivalent, but this one will return ALL | |
771 | // equivalent encodings, regardless the platform, including itself. | |
772 | static wxFontEncodingArray GetAllEquivalents(wxFontEncoding enc); | |
773 | ||
dd9f7fea | 774 | // Return True if [any text in] one multibyte encoding can be |
d14a1e28 RD |
775 | // converted to another one losslessly. |
776 | // | |
777 | // Do not call this with wxFONTENCODING_UNICODE, it doesn't make | |
778 | // sense (always works in one sense and always depends on the text | |
779 | // to convert in the other) | |
780 | static bool CanConvert(wxFontEncoding encIn, wxFontEncoding encOut); | |
781 | ||
782 | %pythoncode { def __nonzero__(self): return self.IsOk() } | |
68bc8549 RD |
783 | }; |
784 | ||
785 | ||
68bc8549 | 786 | |
68bc8549 | 787 | |
d14a1e28 RD |
788 | //--------------------------------------------------------------------------- |
789 | ||
790 | %pythoncode "_intl_ex.py" | |
68bc8549 | 791 | |
d14a1e28 | 792 | //--------------------------------------------------------------------------- |