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