]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_intl.i
Commit Carsten Fuchs' patch for separating wxGLCanvas
[wxWidgets.git] / wxPython / src / _intl.i
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: _intl.i
3 // Purpose: SWIG interface file for wxLocale and related classes
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
13 // Not a %module
14
15
16 //---------------------------------------------------------------------------
17
18 %{
19 #include <locale.h>
20 %}
21
22 //---------------------------------------------------------------------------
23 %newgroup
24
25 enum wxLayoutDirection
26 {
27 wxLayout_Default,
28 wxLayout_LeftToRight,
29 wxLayout_RightToLeft
30 };
31
32
33 enum wxLanguage
34 {
35 // user's default/preffered language as got from OS:
36 wxLANGUAGE_DEFAULT,
37 // unknown language, if wxLocale::GetSystemLanguage fails:
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
273
274 //---------------------------------------------------------------------------
275
276
277 // wxLanguageInfo: encapsulates wxLanguage to OS native lang.desc.
278 // translation information
279 struct wxLanguageInfo
280 {
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
311
312 //---------------------------------------------------------------------------
313
314 class wxLocale
315 {
316 public:
317 // ctor & dtor
318 // -----------
319 %extend {
320 wxLocale(int language = -1,
321 int flags = wxLOCALE_LOAD_DEFAULT | wxLOCALE_CONV_ENCODING) {
322 wxLocale* loc;
323 if (language == -1)
324 loc = new wxLocale();
325 else
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;
333 }
334 }
335
336 // restores old locale
337 ~wxLocale();
338
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 }
365
366
367
368 %pythoncode {
369 def Init(self, *_args, **_kwargs):
370 if type(_args[0]) in [type(''), type(u'')]:
371 val = self.Init1(*_args, **_kwargs)
372 else:
373 val = self.Init2(*_args, **_kwargs)
374 return val
375 }
376
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
395 // return True if the locale was set successfully
396 bool IsOk() const;
397 %pythoncode { def __nonzero__(self): return self.IsOk() };
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 //
426 // Returns 'True' if it was successfully loaded
427 bool AddCatalog(const wxString& szDomain);
428
429 // check if the given catalog is loaded
430 bool IsLoaded(const wxString& szDomain) const;
431
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
437 // Returns language name in English or empty string if the language
438 // is not in database
439 static wxString GetLanguageName(int lang);
440
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
448 // Add custom language to the list of known languages.
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
469 };
470
471 //---------------------------------------------------------------------------
472
473 %{
474 class wxPyLocale : public wxLocale
475 {
476 public:
477 wxPyLocale();
478
479 wxPyLocale(const wxChar *szName, // name (for messages)
480 const wxChar *szShort = (const wxChar *) NULL, // dir prefix (for msg files)
481 const wxChar *szLocale = (const wxChar *) NULL, // locale (for setlocale)
482 bool bLoadDefault = true, // preload wxstd.mo?
483 bool bConvertEncoding = false); // convert Win<->Unix if necessary?
484
485 wxPyLocale(int language, // wxLanguage id or custom language
486 int flags = wxLOCALE_LOAD_DEFAULT | wxLOCALE_CONV_ENCODING);
487
488 ~wxPyLocale();
489
490 virtual const wxChar *GetString(const wxChar *szOrigString,
491 const wxChar *szDomain = NULL) const;
492 virtual const wxChar *GetString(const wxChar *szOrigString,
493 const wxChar *szOrigString2, size_t n,
494 const wxChar *szDomain = NULL) const;
495
496 virtual wxChar *GetSingularString(const wxChar *szOrigString,
497 const wxChar *szDomain = NULL) const;
498 virtual wxChar *GetPluralString(const wxChar *szOrigString,
499 const wxChar *szOrigString2, size_t n,
500 const wxChar *szDomain = NULL) const;
501
502 PYPRIVATE;
503 private:
504 DECLARE_NO_COPY_CLASS(wxPyLocale)
505 };
506
507 wxPyLocale::wxPyLocale() : wxLocale()
508 {
509 }
510
511 wxPyLocale::wxPyLocale(const wxChar *szName, // name (for messages)
512 const wxChar *szShort, // dir prefix (for msg files)
513 const wxChar *szLocale, // locale (for setlocale)
514 bool bLoadDefault, // preload wxstd.mo?
515 bool bConvertEncoding) // convert Win<->Unix if necessary?
516 : wxLocale(szName, szShort, szLocale, bLoadDefault, bConvertEncoding)
517 {
518 }
519
520 wxPyLocale::wxPyLocale(int language, // wxLanguage id or custom language
521 int flags) : wxLocale(language, flags)
522 {
523 }
524
525 wxPyLocale::~wxPyLocale()
526 {
527 }
528
529 const wxChar *wxPyLocale::GetString(const wxChar *szOrigString,
530 const wxChar *szDomain) const
531 {
532 wxChar *str = GetSingularString(szOrigString, szDomain);
533 return (str != NULL) ? str : wxLocale::GetString(szOrigString, szDomain);
534 }
535
536 const wxChar *wxPyLocale::GetString(const wxChar *szOrigString,
537 const wxChar *szOrigString2, size_t n,
538 const wxChar *szDomain) const
539 {
540 wxChar *str = GetPluralString(szOrigString, szOrigString2, n, szDomain);
541 return (str != NULL) ? str : wxLocale::GetString(szOrigString, szOrigString2, n, szDomain);
542 }
543
544 wxChar *wxPyLocale::GetSingularString(const wxChar *szOrigString,
545 const wxChar *szDomain) const
546 {
547 bool found;
548 static wxString str;
549 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.
550 wxPyBlock_t blocked = wxPyBeginBlockThreads();
551 if((found=wxPyCBH_findCallback(m_myInst, "GetSingularString"))) {
552 PyObject* param1 = wx2PyString(szOrigString);
553 PyObject* param2 = wx2PyString(szDomain);
554 PyObject* ret = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(OO)", param1, param2));
555 Py_DECREF(param1);
556 Py_DECREF(param2);
557 if (ret) {
558 str = Py2wxString(ret);
559 Py_DECREF(ret);
560 }
561 }
562 wxPyEndBlockThreads(blocked);
563 return (found ? (wxChar*)str.c_str() : NULL);
564 }
565
566 wxChar *wxPyLocale::GetPluralString(const wxChar *szOrigString,
567 const wxChar *szOrigString2, size_t n,
568 const wxChar *szDomain) const
569 {
570 bool found;
571 static wxString str;
572 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.
573 wxPyBlock_t blocked = wxPyBeginBlockThreads();
574 if((found=wxPyCBH_findCallback(m_myInst, "GetPluralString"))) {
575 PyObject* param1 = wx2PyString(szOrigString);
576 PyObject* param2 = wx2PyString(szOrigString2);
577 PyObject* param4 = wx2PyString(szDomain);
578 PyObject* ret = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(OOiO)", param1, param2, (int)n, param4));
579 Py_DECREF(param1);
580 Py_DECREF(param2);
581 Py_DECREF(param4);
582 if( ret) {
583 str = Py2wxString(ret);
584 Py_DECREF(ret);
585 }
586 }
587 wxPyEndBlockThreads(blocked);
588 return (found ? (wxChar*)str.c_str() : NULL);
589 }
590 %}
591
592
593 class wxPyLocale : public wxLocale
594 {
595 public:
596 %pythonAppend wxPyLocale "self._setCallbackInfo(self, PyLocale)"
597
598 // ctor & dtor
599 // -----------
600 %extend {
601 wxPyLocale(int language = -1,
602 int flags = wxLOCALE_LOAD_DEFAULT | wxLOCALE_CONV_ENCODING) {
603 wxPyLocale* loc;
604 if (language == -1)
605 loc = new wxPyLocale();
606 else
607 loc = new wxPyLocale(language, flags);
608 // Python before 2.4 needs to have LC_NUMERIC set to "C" in order
609 // for the floating point conversions and such to work right.
610 %#if PY_VERSION_HEX < 0x02040000
611 setlocale(LC_NUMERIC, "C");
612 %#endif
613 return loc;
614 }
615 }
616 ~wxPyLocale();
617
618 void _setCallbackInfo(PyObject* self, PyObject* _class);
619
620 virtual const wxChar *GetSingularString(const wxChar *szOrigString,
621 const wxChar *szDomain = NULL) const;
622 virtual const wxChar *GetPluralString(const wxChar *szOrigString,
623 const wxChar *szOrigString2, size_t n,
624 const wxChar *szDomain = NULL) const;
625 };
626
627 //---------------------------------------------------------------------------
628
629 // get the current locale object (note that it may be NULL!)
630 wxLocale* wxGetLocale();
631
632 // get the translation of the string in the current locale
633 %nokwargs wxGetTranslation;
634 wxString wxGetTranslation(const wxString& str);
635 wxString wxGetTranslation(const wxString& str, const wxString& domain);
636 wxString wxGetTranslation(const wxString& str, const wxString& strPlural, size_t n);
637 wxString wxGetTranslation(const wxString& str, const wxString& strPlural, size_t n, const wxString& domain);
638
639 //---------------------------------------------------------------------------
640 %newgroup
641
642
643 // wxEncodingConverter
644 // This class is capable of converting strings between any two
645 // 8bit encodings/charsets. It can also convert from/to Unicode
646
647
648 %typemap(out) wxFontEncodingArray {
649 $result = PyList_New(0);
650 for (size_t i=0; i < $1.GetCount(); i++) {
651 PyObject* number = PyInt_FromLong($1.Item(i));
652 PyList_Append($result, number);
653 Py_DECREF(number);
654 }
655 }
656
657
658 enum
659 {
660 wxCONVERT_STRICT,
661 wxCONVERT_SUBSTITUTE
662 };
663
664
665 enum
666 {
667 wxPLATFORM_CURRENT = -1,
668
669 wxPLATFORM_UNIX = 0,
670 wxPLATFORM_WINDOWS,
671 wxPLATFORM_OS2,
672 wxPLATFORM_MAC
673 };
674
675
676 class wxEncodingConverter : public wxObject
677 {
678 public:
679
680 wxEncodingConverter();
681 ~wxEncodingConverter();
682
683
684 // Initialize convertion. Both output or input encoding may
685 // be wxFONTENCODING_UNICODE, but only if wxUSE_WCHAR_T is set to 1.
686 //
687 // All subsequent calls to Convert() will interpret it's argument
688 // as a string in input_enc encoding and will output string in
689 // output_enc encoding.
690 //
691 // You must call this method before calling Convert. You may call
692 // it more than once in order to switch to another conversion
693 //
694 // Method affects behaviour of Convert() in case input character
695 // cannot be converted because it does not exist in output encoding:
696 // wxCONVERT_STRICT --
697 // follow behaviour of GNU Recode - just copy unconvertable
698 // characters to output and don't change them (it's integer
699 // value will stay the same)
700 // wxCONVERT_SUBSTITUTE --
701 // try some (lossy) substitutions - e.g. replace
702 // unconvertable latin capitals with acute by ordinary
703 // capitals, replace en-dash or em-dash by '-' etc.
704 // both modes gurantee that output string will have same length
705 // as input string
706 //
707 // Returns False if given conversion is impossible, True otherwise
708 // (conversion may be impossible either if you try to convert
709 // to Unicode with non-Unicode build of wxWindows or if input
710 // or output encoding is not supported.)
711 bool Init(wxFontEncoding input_enc, wxFontEncoding output_enc, int method = wxCONVERT_STRICT);
712
713
714 // TODO: Need to do something about unicode mode...
715
716 // Convert input string according to settings passed to Init.
717 // Note that you must call Init before using Convert!
718 wxString Convert(const wxString& input);
719
720 // void Convert(const char* input, char* output);
721
722 // #if wxUSE_WCHAR_T
723 // void Convert(const char* input, wchar_t* output);
724 // void Convert(const wchar_t* input, char* output);
725 // void Convert(const wchar_t* input, wchar_t* output);
726 // void Convert(wchar_t* str) { Convert(str, str); }
727 // #endif
728
729
730
731 // Return equivalent(s) for given font that are used
732 // under given platform. wxPLATFORM_CURRENT means the plaform
733 // this binary was compiled for
734 //
735 // Examples:
736 // current platform enc returned value
737 // -----------------------------------------------------
738 // unix CP1250 {ISO8859_2}
739 // unix ISO8859_2 {}
740 // windows ISO8859_2 {CP1250}
741 //
742 // Equivalence is defined in terms of convertibility:
743 // 2 encodings are equivalent if you can convert text between
744 // then without loosing information (it may - and will - happen
745 // that you loose special chars like quotation marks or em-dashes
746 // but you shouldn't loose any diacritics and language-specific
747 // characters when converting between equivalent encodings).
748 //
749 // Convert() method is not limited to converting between
750 // equivalent encodings, it can convert between arbitrary
751 // two encodings!
752 //
753 // Remember that this function does _NOT_ check for presence of
754 // fonts in system. It only tells you what are most suitable
755 // encodings. (It usually returns only one encoding)
756 //
757 // Note that argument enc itself may be present in returned array!
758 // (so that you can -- as a side effect -- detect whether the
759 // encoding is native for this platform or not)
760 static wxFontEncodingArray GetPlatformEquivalents(wxFontEncoding enc,
761 int platform = wxPLATFORM_CURRENT);
762
763 // Similar to GetPlatformEquivalent, but this one will return ALL
764 // equivalent encodings, regardless the platform, including itself.
765 static wxFontEncodingArray GetAllEquivalents(wxFontEncoding enc);
766
767 // Return True if [any text in] one multibyte encoding can be
768 // converted to another one losslessly.
769 //
770 // Do not call this with wxFONTENCODING_UNICODE, it doesn't make
771 // sense (always works in one sense and always depends on the text
772 // to convert in the other)
773 static bool CanConvert(wxFontEncoding encIn, wxFontEncoding encOut);
774
775 %pythoncode { def __nonzero__(self): return self.IsOk() }
776 };
777
778
779
780
781 //---------------------------------------------------------------------------
782
783 %pythoncode "_intl_ex.py"
784
785 //---------------------------------------------------------------------------