1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: SWIG interface file for wxLocale and related classes
9 // Copyright: (c) 2002 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
16 //---------------------------------------------------------------------------
22 //---------------------------------------------------------------------------
25 enum wxLayoutDirection
35 // user's default/preffered language as got from OS:
37 // unknown language, if wxLocale::GetSystemLanguage fails:
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,
67 wxLANGUAGE_AZERI_CYRILLIC,
68 wxLANGUAGE_AZERI_LATIN,
71 wxLANGUAGE_BELARUSIAN,
82 wxLANGUAGE_CHINESE_SIMPLIFIED,
83 wxLANGUAGE_CHINESE_TRADITIONAL,
84 wxLANGUAGE_CHINESE_HONGKONG,
85 wxLANGUAGE_CHINESE_MACAU,
86 wxLANGUAGE_CHINESE_SINGAPORE,
87 wxLANGUAGE_CHINESE_TAIWAN,
93 wxLANGUAGE_DUTCH_BELGIAN,
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,
117 wxLANGUAGE_FRENCH_BELGIAN,
118 wxLANGUAGE_FRENCH_CANADIAN,
119 wxLANGUAGE_FRENCH_LUXEMBOURG,
120 wxLANGUAGE_FRENCH_MONACO,
121 wxLANGUAGE_FRENCH_SWISS,
126 wxLANGUAGE_GERMAN_AUSTRIAN,
127 wxLANGUAGE_GERMAN_BELGIUM,
128 wxLANGUAGE_GERMAN_LIECHTENSTEIN,
129 wxLANGUAGE_GERMAN_LUXEMBOURG,
130 wxLANGUAGE_GERMAN_SWISS,
132 wxLANGUAGE_GREENLANDIC,
138 wxLANGUAGE_HUNGARIAN,
139 wxLANGUAGE_ICELANDIC,
140 wxLANGUAGE_INDONESIAN,
141 wxLANGUAGE_INTERLINGUA,
142 wxLANGUAGE_INTERLINGUE,
143 wxLANGUAGE_INUKTITUT,
147 wxLANGUAGE_ITALIAN_SWISS,
152 wxLANGUAGE_KASHMIRI_INDIA,
155 wxLANGUAGE_KINYARWANDA,
165 wxLANGUAGE_LITHUANIAN,
166 wxLANGUAGE_MACEDONIAN,
169 wxLANGUAGE_MALAYALAM,
170 wxLANGUAGE_MALAY_BRUNEI_DARUSSALAM,
171 wxLANGUAGE_MALAY_MALAYSIA,
176 wxLANGUAGE_MOLDAVIAN,
177 wxLANGUAGE_MONGOLIAN,
180 wxLANGUAGE_NEPALI_INDIA,
181 wxLANGUAGE_NORWEGIAN_BOKMAL,
182 wxLANGUAGE_NORWEGIAN_NYNORSK,
188 wxLANGUAGE_PORTUGUESE,
189 wxLANGUAGE_PORTUGUESE_BRAZILIAN,
192 wxLANGUAGE_RHAETO_ROMANCE,
195 wxLANGUAGE_RUSSIAN_UKRAINE,
199 wxLANGUAGE_SCOTS_GAELIC,
201 wxLANGUAGE_SERBIAN_CYRILLIC,
202 wxLANGUAGE_SERBIAN_LATIN,
203 wxLANGUAGE_SERBO_CROATIAN,
208 wxLANGUAGE_SINHALESE,
211 wxLANGUAGE_SLOVENIAN,
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,
237 wxLANGUAGE_SWEDISH_FINLAND,
252 wxLANGUAGE_UKRAINIAN,
254 wxLANGUAGE_URDU_INDIA,
255 wxLANGUAGE_URDU_PAKISTAN,
257 wxLANGUAGE_UZBEK_CYRILLIC,
258 wxLANGUAGE_UZBEK_LATIN,
259 wxLANGUAGE_VIETNAMESE,
269 // for custom, user-defined languages:
270 wxLANGUAGE_USER_DEFINED
274 //---------------------------------------------------------------------------
277 // wxLanguageInfo: encapsulates wxLanguage to OS native lang.desc.
278 // translation information
279 struct wxLanguageInfo
281 int Language; // wxLanguage id
282 wxString CanonicalName; // Canonical name, e.g. fr_FR
283 wxString Description; // human-readable name of the language
286 // wxLocaleCategory: the category of locale settings
287 enum wxLocaleCategory
295 // wxLocaleInfo: the items understood by wxLocale::GetInfo()
298 wxLOCALE_THOUSANDS_SEP,
299 wxLOCALE_DECIMAL_POINT
303 // wxLocale: encapsulates all language dependent settings, including current
304 // message catalogs, date, time and currency formats (TODO) &c
305 enum wxLocaleInitFlags
307 wxLOCALE_LOAD_DEFAULT = 0x0001, // load wxwin.mo?
308 wxLOCALE_CONV_ENCODING = 0x0002 // convert encoding on the fly?
312 //---------------------------------------------------------------------------
320 wxLocale(int language = -1,
321 int flags = wxLOCALE_LOAD_DEFAULT | wxLOCALE_CONV_ENCODING) {
324 loc = new wxLocale();
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");
336 // restores old locale
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");
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");
369 def Init(self, *_args, **_kwargs):
370 if type(_args[0]) in [type(''), type(u'')]:
371 val = self.Init1(*_args, **_kwargs)
373 val = self.Init2(*_args, **_kwargs)
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();
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();
385 // get the string describing the system encoding, return empty string if
386 // couldn't be determined
387 static wxString GetSystemEncodingName();
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);
395 // return True if the locale was set successfully
397 %pythoncode { def __nonzero__(self): return self.IsOk() };
399 // returns locale name
400 wxString GetLocale() const;
402 // return current locale wxLanguage value
403 int GetLanguage() const;
405 // return locale name to be passed to setlocale()
406 wxString GetSysName() const;
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;
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
417 // This only applies to subsequent invocations of AddCatalog()!
418 static void AddCatalogLookupPathPrefix(const wxString& prefix);
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().
424 // The loaded catalog will be used for message lookup by GetString().
426 // Returns 'True' if it was successfully loaded
427 bool AddCatalog(const wxString& szDomain);
429 // check if the given catalog is loaded
430 bool IsLoaded(const wxString& szDomain) const;
432 // Retrieve the language info struct for the given language
434 // Returns NULL if no info found, pointer must *not* be deleted by caller
435 static const wxLanguageInfo *GetLanguageInfo(int lang);
437 // Returns language name in English or empty string if the language
438 // is not in database
439 static wxString GetLanguageName(int lang);
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...")
445 // Returns NULL if no info found, pointer must *not* be deleted by caller
446 static const wxLanguageInfo *FindLanguageInfo(const wxString& locale);
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);
453 // retrieve the translation for a string in all loaded domains unless
454 // the szDomain parameter is specified (and then only this domain is
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)
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;
466 // Returns the current short name for the locale
467 const wxString& GetName() const;
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`");
478 //---------------------------------------------------------------------------
481 class wxPyLocale : public wxLocale
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?
492 wxPyLocale(int language, // wxLanguage id or custom language
493 int flags = wxLOCALE_LOAD_DEFAULT | wxLOCALE_CONV_ENCODING);
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;
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;
511 DECLARE_NO_COPY_CLASS(wxPyLocale)
514 wxPyLocale::wxPyLocale() : wxLocale()
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)
527 wxPyLocale::wxPyLocale(int language, // wxLanguage id or custom language
528 int flags) : wxLocale(language, flags)
532 wxPyLocale::~wxPyLocale()
536 const wxChar *wxPyLocale::GetString(const wxChar *szOrigString,
537 const wxChar *szDomain) const
539 wxChar *str = GetSingularString(szOrigString, szDomain);
540 return (str != NULL) ? str : wxLocale::GetString(szOrigString, szDomain);
543 const wxChar *wxPyLocale::GetString(const wxChar *szOrigString,
544 const wxChar *szOrigString2, size_t n,
545 const wxChar *szDomain) const
547 wxChar *str = GetPluralString(szOrigString, szOrigString2, n, szDomain);
548 return (str != NULL) ? str : wxLocale::GetString(szOrigString, szOrigString2, n, szDomain);
551 wxChar *wxPyLocale::GetSingularString(const wxChar *szOrigString,
552 const wxChar *szDomain) const
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));
565 str = Py2wxString(ret);
569 wxPyEndBlockThreads(blocked);
570 return (found ? (wxChar*)str.c_str() : NULL);
573 wxChar *wxPyLocale::GetPluralString(const wxChar *szOrigString,
574 const wxChar *szOrigString2, size_t n,
575 const wxChar *szDomain) const
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));
590 str = Py2wxString(ret);
594 wxPyEndBlockThreads(blocked);
595 return (found ? (wxChar*)str.c_str() : NULL);
600 class wxPyLocale : public wxLocale
603 %pythonAppend wxPyLocale "self._setCallbackInfo(self, PyLocale)"
608 wxPyLocale(int language = -1,
609 int flags = wxLOCALE_LOAD_DEFAULT | wxLOCALE_CONV_ENCODING) {
612 loc = new wxPyLocale();
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");
625 void _setCallbackInfo(PyObject* self, PyObject* _class);
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;
634 //---------------------------------------------------------------------------
636 // get the current locale object (note that it may be NULL!)
637 wxLocale* wxGetLocale();
639 // get the translation of the string in the current locale
640 %nokwargs wxGetTranslation;
641 wxString wxGetTranslation(const wxString& str);
642 wxString wxGetTranslation(const wxString& str, const wxString& domain);
643 wxString wxGetTranslation(const wxString& str, const wxString& strPlural, size_t n);
644 wxString wxGetTranslation(const wxString& str, const wxString& strPlural, size_t n, const wxString& domain);
646 //---------------------------------------------------------------------------
650 // wxEncodingConverter
651 // This class is capable of converting strings between any two
652 // 8bit encodings/charsets. It can also convert from/to Unicode
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);
674 wxPLATFORM_CURRENT = -1,
683 class wxEncodingConverter : public wxObject
687 wxEncodingConverter();
688 ~wxEncodingConverter();
691 // Initialize convertion. Both output or input encoding may
692 // be wxFONTENCODING_UNICODE, but only if wxUSE_WCHAR_T is set to 1.
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.
698 // You must call this method before calling Convert. You may call
699 // it more than once in order to switch to another conversion
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
714 // Returns False if given conversion is impossible, True otherwise
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);
721 // TODO: Need to do something about unicode mode...
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);
727 // void Convert(const char* input, char* output);
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); }
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
743 // current platform enc returned value
744 // -----------------------------------------------------
745 // unix CP1250 {ISO8859_2}
747 // windows ISO8859_2 {CP1250}
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).
756 // Convert() method is not limited to converting between
757 // equivalent encodings, it can convert between arbitrary
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)
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);
770 // Similar to GetPlatformEquivalent, but this one will return ALL
771 // equivalent encodings, regardless the platform, including itself.
772 static wxFontEncodingArray GetAllEquivalents(wxFontEncoding enc);
774 // Return True if [any text in] one multibyte encoding can be
775 // converted to another one losslessly.
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);
782 %pythoncode { def __nonzero__(self): return self.IsOk() }
788 //---------------------------------------------------------------------------
790 %pythoncode "_intl_ex.py"
792 //---------------------------------------------------------------------------