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