+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;
+};
+
+//---------------------------------------------------------------------------