X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/d14a1e28567de23c586bc80017073d0c39f8d18f..26ee65c723cf55822c540506f064ec11d9b26858:/wxPython/src/_intl.i?ds=sidebyside diff --git a/wxPython/src/_intl.i b/wxPython/src/_intl.i index ba436a9a61..c8dff0c6db 100644 --- a/wxPython/src/_intl.i +++ b/wxPython/src/_intl.i @@ -16,12 +16,12 @@ //--------------------------------------------------------------------------- %{ +#include %} //--------------------------------------------------------------------------- %newgroup - enum wxLanguage { // user's default/preffered language as got from OS: @@ -308,20 +308,54 @@ class wxLocale public: // ctor & dtor // ----------- - wxLocale(int language = wxLANGUAGE_DEFAULT, - int flags = wxLOCALE_LOAD_DEFAULT | wxLOCALE_CONV_ENCODING); + %extend { + wxLocale(int language = -1, + int flags = wxLOCALE_LOAD_DEFAULT | wxLOCALE_CONV_ENCODING) { + wxLocale* loc; + if (language == -1) + loc = new wxLocale(); + else + loc = new wxLocale(language, flags); + // Python before 2.4 needs to have LC_NUMERIC set to "C" in order + // for the floating point conversions and such to work right. +%#if PY_VERSION_HEX < 0x02040000 + setlocale(LC_NUMERIC, "C"); +%#endif + return loc; + } + } // restores old locale ~wxLocale(); - %name(Init1)bool Init(const wxString& szName, - const wxString& szShort = wxPyEmptyString, - const wxString& szLocale = wxPyEmptyString, - bool bLoadDefault = TRUE, - bool bConvertEncoding = FALSE); + %extend { + bool Init1(const wxString& name, + const wxString& shortName = wxPyEmptyString, + const wxString& locale = wxPyEmptyString, + bool bLoadDefault = true, + bool bConvertEncoding = false) { + bool rc = self->Init(name, shortName, locale, bLoadDefault, bConvertEncoding); + // Python before 2.4 needs to have LC_NUMERIC set to "C" in order + // for the floating point conversions and such to work right. +%#if PY_VERSION_HEX < 0x02040000 + setlocale(LC_NUMERIC, "C"); +%#endif + return rc; + } + + bool Init2(int language = wxLANGUAGE_DEFAULT, + int flags = wxLOCALE_LOAD_DEFAULT | wxLOCALE_CONV_ENCODING) { + bool rc = self->Init(language, flags); + // Python before 2.4 needs to have LC_NUMERIC set to "C" in order + // for the floating point conversions and such to work right. +%#if PY_VERSION_HEX < 0x02040000 + setlocale(LC_NUMERIC, "C"); +%#endif + return rc; + } + } - %name(Init2) bool Init(int language = wxLANGUAGE_DEFAULT, - int flags = wxLOCALE_LOAD_DEFAULT | wxLOCALE_CONV_ENCODING); + %pythoncode { def Init(self, *_args, **_kwargs): @@ -350,7 +384,7 @@ public: // is used, the US default value is returned if everything else fails // static wxString GetInfo(wxLocaleInfo index, wxLocaleCategory cat); - // return TRUE if the locale was set successfully + // return True if the locale was set successfully bool IsOk() const; %pythoncode { def __nonzero__(self): return self.IsOk() }; @@ -381,11 +415,14 @@ public: // // The loaded catalog will be used for message lookup by GetString(). // - // Returns 'true' if it was successfully loaded - bool AddCatalog(const wxString& szDomain); + // Returns 'True' if it was successfully loaded + bool AddCatalog(const wxString& domain); + // check if the given locale is provided by OS and C run time + static bool IsAvailable(int lang); + // check if the given catalog is loaded - bool IsLoaded(const wxString& szDomain) const; + bool IsLoaded(const wxString& domain) const; // Retrieve the language info struct for the given language // @@ -418,23 +455,191 @@ public: // // domains are searched in the last to first order, i.e. catalogs // added later override those added before. - wxString GetString(const wxString& szOrigString, - const wxString& szDomain = wxPyEmptyString) const; + wxString GetString(const wxString& origString, + const wxString& domain = wxPyEmptyString) const; // Returns the current short name for the locale const wxString& GetName() const; + + %property(CanonicalName, GetCanonicalName, doc="See `GetCanonicalName`"); + %property(Language, GetLanguage, doc="See `GetLanguage`"); + %property(Locale, GetLocale, doc="See `GetLocale`"); + %property(Name, GetName, doc="See `GetName`"); + %property(String, GetString, doc="See `GetString`"); + %property(SysName, GetSysName, doc="See `GetSysName`"); +}; + +//--------------------------------------------------------------------------- + +%{ +class wxPyLocale : public wxLocale +{ +public: + wxPyLocale(); + + wxPyLocale(const wxString& name, // name (for messages) + const wxString& shortName = wxPyEmptyString, // dir prefix (for msg files) + const wxString& locale = wxPyEmptyString, // locale (for setlocale) + bool bLoadDefault = true, // preload wxstd.mo? + bool bConvertEncoding = false); // convert Win<->Unix if necessary? + + wxPyLocale(int language, // wxLanguage id or custom language + int flags = wxLOCALE_LOAD_DEFAULT | wxLOCALE_CONV_ENCODING); + + ~wxPyLocale(); + + virtual const wxString& GetString(const wxString& origString, + const wxString& domain = wxPyEmptyString) const; + virtual const wxString& GetString(const wxString& origString, + const wxString& origString2, + size_t n, + const wxString& domain = wxPyEmptyString) const; + + virtual const wxString& GetSingularString(const wxString& origString, + const wxString& domain = wxPyEmptyString) const; + virtual const wxString& GetPluralString(const wxString& origString, + const wxString& origString2, + size_t n, + const wxString& domain = wxPyEmptyString) const; + + + PYPRIVATE; +private: + DECLARE_NO_COPY_CLASS(wxPyLocale) }; +wxPyLocale::wxPyLocale() : wxLocale() +{ +} + +wxPyLocale::wxPyLocale(const wxString& name, // name (for messages) + const wxString& shortName, // dir prefix (for msg files) + const wxString& locale, // locale (for setlocale) + bool bLoadDefault, // preload wxstd.mo? + bool bConvertEncoding) // convert Win<->Unix if necessary? + : wxLocale(name, shortName, locale, bLoadDefault, bConvertEncoding) +{ +} + +wxPyLocale::wxPyLocale(int language, // wxLanguage id or custom language + int flags) : wxLocale(language, flags) +{ +} + +wxPyLocale::~wxPyLocale() +{ +} + +const wxString& wxPyLocale::GetString(const wxString& origString, + const wxString& domain) const +{ + return GetSingularString(origString, domain); +} +const wxString& wxPyLocale::GetString(const wxString& origString, + const wxString& origString2, + size_t n, + const wxString& domain) const +{ + return GetPluralString(origString, origString2, n, domain); +} + +const wxString& wxPyLocale::GetSingularString(const wxString& origString, + const wxString& domain) const +{ + bool found; + wxString str( _T("error in translation")); + wxPyBlock_t blocked = wxPyBeginBlockThreads(); + if ((found=wxPyCBH_findCallback(m_myInst, "GetSingularString"))) { + PyObject* param1 = wx2PyString(origString); + PyObject* param2 = wx2PyString(domain); + PyObject* ret = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(OO)", param1, param2)); + Py_DECREF(param1); + Py_DECREF(param2); + if (ret) { + str = Py2wxString(ret); + Py_DECREF(ret); + } + } + wxPyEndBlockThreads(blocked); + return (found ? str : wxLocale::GetString(origString, domain)); +} + +const wxString& wxPyLocale::GetPluralString(const wxString& origString, + const wxString& origString2, size_t n, + const wxString& domain) const +{ + bool found; + wxString str( _T("error in translation")); + wxPyBlock_t blocked = wxPyBeginBlockThreads(); + if ((found=wxPyCBH_findCallback(m_myInst, "GetPluralString"))) { + PyObject* param1 = wx2PyString(origString); + PyObject* param2 = wx2PyString(origString2); + PyObject* param4 = wx2PyString(domain); + PyObject* ret = wxPyCBH_callCallbackObj(m_myInst, + Py_BuildValue("(OOiO)", + param1, param2, + (int)n, param4)); + Py_DECREF(param1); + Py_DECREF(param2); + Py_DECREF(param4); + if( ret) { + str = Py2wxString(ret); + Py_DECREF(ret); + } + } + wxPyEndBlockThreads(blocked); + return (found ? str : wxLocale::GetString(origString, origString2, n, domain) ); +} +%} + + +class wxPyLocale : public wxLocale +{ +public: + %pythonAppend wxPyLocale setCallbackInfo(PyLocale) + + // ctor & dtor + // ----------- + %extend { + wxPyLocale(int language = -1, + int flags = wxLOCALE_LOAD_DEFAULT | wxLOCALE_CONV_ENCODING) { + wxPyLocale* loc; + if (language == -1) + loc = new wxPyLocale(); + else + loc = new wxPyLocale(language, flags); + // Python before 2.4 needs to have LC_NUMERIC set to "C" in order + // for the floating point conversions and such to work right. +%#if PY_VERSION_HEX < 0x02040000 + setlocale(LC_NUMERIC, "C"); +%#endif + return loc; + } + } + ~wxPyLocale(); + + void _setCallbackInfo(PyObject* self, PyObject* _class); + + virtual const wxString& GetSingularString(const wxString& origString, + const wxString& domain = wxPyEmptyString) const; + virtual const wxString& GetPluralString(const wxString& origString, + const wxString& origString2, size_t n, + const wxString& domain = wxPyEmptyString) const; +}; + +//--------------------------------------------------------------------------- // get the current locale object (note that it may be NULL!) wxLocale* wxGetLocale(); // get the translation of the string in the current locale %nokwargs wxGetTranslation; -wxString wxGetTranslation(const wxString& sz); -wxString wxGetTranslation(const wxString& sz1, const wxString& sz2, size_t n); +wxString wxGetTranslation(const wxString& str); +wxString wxGetTranslation(const wxString& str, const wxString& domain); +wxString wxGetTranslation(const wxString& str, const wxString& strPlural, size_t n); +wxString wxGetTranslation(const wxString& str, const wxString& strPlural, size_t n, const wxString& domain); //--------------------------------------------------------------------------- %newgroup @@ -504,7 +709,7 @@ public: // both modes gurantee that output string will have same length // as input string // - // Returns FALSE if given conversion is impossible, TRUE otherwise + // Returns False if given conversion is impossible, True otherwise // (conversion may be impossible either if you try to convert // to Unicode with non-Unicode build of wxWindows or if input // or output encoding is not supported.) @@ -564,7 +769,7 @@ public: // equivalent encodings, regardless the platform, including itself. static wxFontEncodingArray GetAllEquivalents(wxFontEncoding enc); - // Return true if [any text in] one multibyte encoding can be + // Return True if [any text in] one multibyte encoding can be // converted to another one losslessly. // // Do not call this with wxFONTENCODING_UNICODE, it doesn't make