\membersection{::wxGetTranslation}\label{wxgettranslation}
-\func{const char *}{wxGetTranslation}{\param{const char * }{str}}
+\func{const wxChar *}{wxGetTranslation}{\param{const wxChar* }{str},
+ \param{const wxChar* }{domain = NULL}}
-\func{const char *}{wxGetTranslation}{\param{const char * }{str}, \param{const char * }{strPlural}, \param{size\_t }{n}}
+\func{const wxChar *}{wxGetTranslation}{\param{const wxChar* }{str}, \param{const wxChar* }{strPlural}, \param{size\_t }{n},
+ \param{const wxChar* }{domain = NULL}}}
This function returns the translation of string {\it str} in the current
\helpref{locale}{wxlocale}. If the string is not found in any of the loaded
message catalogs (see \helpref{internationalization overview}{internationalization}), the
original string is returned. In debug build, an error message is logged -- this
-should help to find the strings which were not yet translated. As this function
+should help to find the strings which were not yet translated. If
+{\it domain} is specified then only that domain/catalog is searched
+for a matching string. As this function
is used very often, an alternative (and also common in Unix world) syntax is
provided: the \helpref{\_()}{underscore} macro is defined to do the same thing
as wxGetTranslation.
\membersection{wxXmlResource::wxXmlResource}\label{wxxmlresourcector}
-\func{}{wxXmlResource}{\param{const wxString\& }{filemask}, \param{int }{flags = wxXRC\_USE\_LOCALE}}
+\func{}{wxXmlResource}{\param{const wxString\& }{filemask},
+ \param{int }{flags = wxXRC\_USE\_LOCALE},
+ \param{const wxString& }{domain = wxEmptyString}}
Constructor.
wxXRC\_NO\_SUBCLASSING: subclass property of object nodes will be ignored
(useful for previews in XRC editors).}
-\func{}{wxXmlResource}{\param{int }{flags = wxXRC\_USE\_LOCALE}}
+\docparam{domain}{The name of the gettext catalog to search for
+ translatable strings. By default all loaded catalogs will be
+ searched. This provides a way to allow the strings to only come
+ from a specific catalog.}
+
+\func{}{wxXmlResource}{\param{int }{flags = wxXRC\_USE\_LOCALE},
+ \param{const wxString& }{domain = wxEmptyString}}
Constructor.
XRC files from being reloaded from disk in case they have been modified there
since being last loaded (may slightly speed up loading them).}
+\docparam{domain}{The name of the gettext catalog to search for
+ translatable strings. By default all loaded catalogs will be
+ searched. This provides a way to allow the strings to only come
+ from a specific catalog.}
+
\membersection{wxXmlResource::\destruct{wxXmlResource}}\label{wxxmlresourcedtor}
Returns \true if the resource was successfully unloaded and \false if it hasn't
been found in the list of loaded resources.
+
+
+\membersection{wxXmlResource::GetDomain}\label{wxxmlresourcegetdomain}
+
+\func{wxChar*}{GetDomain}{}
+
+Returns the domain (message catalog) that will be used to load
+translatable strings in the XRC.
+
+
+\membersection{wxXmlResource::SetDomain}\label{wxxmlresourcesetdomain}
+
+\func{wxChar*}{SetDomain}{\param{const wxChar* }{domain}}
+
+Sets the domain (message catalog) that will be used to load
+translatable strings in the XRC.
int flags = wxLOCALE_LOAD_DEFAULT | wxLOCALE_CONV_ENCODING);
// restores old locale
- ~wxLocale();
+ virtual ~wxLocale();
// Try to get user's (or OS's) preferred language setting.
// Return wxLANGUAGE_UNKNOWN if language-guessing algorithm failed
//
// domains are searched in the last to first order, i.e. catalogs
// added later override those added before.
- const wxChar *GetString(const wxChar *szOrigString,
- const wxChar *szDomain = NULL) const;
+ virtual const wxChar *GetString(const wxChar *szOrigString,
+ const wxChar *szDomain = NULL) const;
// plural form version of the same:
- const wxChar *GetString(const wxChar *szOrigString,
- const wxChar *szOrigString2,
- size_t n,
- const wxChar *szDomain = NULL) const;
+ virtual const wxChar *GetString(const wxChar *szOrigString,
+ const wxChar *szOrigString2,
+ size_t n,
+ const wxChar *szDomain = NULL) const;
// Returns the current short name for the locale
const wxString& GetName() const { return m_strShort; }
extern WXDLLIMPEXP_BASE wxLocale* wxGetLocale();
// get the translation of the string in the current locale
-inline const wxChar *wxGetTranslation(const wxChar *sz)
+inline const wxChar *wxGetTranslation(const wxChar *sz, const wxChar* domain=NULL)
{
wxLocale *pLoc = wxGetLocale();
if (pLoc)
- return pLoc->GetString(sz);
+ return pLoc->GetString(sz, domain);
else
return sz;
}
inline const wxChar *wxGetTranslation(const wxChar *sz1, const wxChar *sz2,
- size_t n)
+ size_t n, const wxChar* domain=NULL)
{
wxLocale *pLoc = wxGetLocale();
if (pLoc)
- return pLoc->GetString(sz1, sz2, n);
+ return pLoc->GetString(sz1, sz2, n, domain);
else
return n == 1 ? sz1 : sz2;
}
// Constructor.
// Flags: wxXRC_USE_LOCALE
// translatable strings will be translated via _()
+ // using the given domain if specified
// wxXRC_NO_SUBCLASSING
// subclass property of object nodes will be ignored
// (useful for previews in XRC editors)
// wxXRC_NO_RELOADING
// don't check the modification time of the XRC files and
// reload them if they have changed on disk
- wxXmlResource(int flags = wxXRC_USE_LOCALE);
+ wxXmlResource(int flags = wxXRC_USE_LOCALE,
+ const wxString& domain=wxEmptyString);
// Constructor.
// Flags: wxXRC_USE_LOCALE
// translatable strings will be translated via _()
+ // using the given domain if specified
// wxXRC_NO_SUBCLASSING
// subclass property of object nodes will be ignored
// (useful for previews in XRC editors)
- wxXmlResource(const wxString& filemask, int flags = wxXRC_USE_LOCALE);
+ wxXmlResource(const wxString& filemask, int flags = wxXRC_USE_LOCALE,
+ const wxString& domain=wxEmptyString);
// Destructor.
~wxXmlResource();
// Set flags after construction.
void SetFlags(int flags) { m_flags = flags; }
+ // Get/Set the domain to be passed to the translation functions, defaults to NULL.
+ wxChar* GetDomain() const { return m_domain; }
+ void SetDomain(const wxChar* domain);
+
protected:
// Scans the resources list for unloaded files and loads them. Also reloads
// files that have been modified since last loading.
wxFileSystem& GetCurFileSystem() { return m_curFileSystem; }
#endif
+ // domain to pass to translation functions, if any.
+ wxChar* m_domain;
+
friend class wxXmlResourceHandler;
friend class wxXmlResourceModule;
// add to the list
wxString str = GetNodeContent(m_node);
if (m_resource->GetFlags() & wxXRC_USE_LOCALE)
- str = wxGetTranslation(str);
+ str = wxGetTranslation(str, m_resource->GetDomain());
strList.Add(str);
return NULL;
}
// add to the list
wxString str = GetNodeContent(m_node);
if (m_resource->GetFlags() & wxXRC_USE_LOCALE)
- str = wxGetTranslation(str);
+ str = wxGetTranslation(str, m_resource->GetDomain());
strList.Add(str);
return NULL;
// add to the list
wxString str = GetNodeContent(m_node);
if (m_resource->GetFlags() & wxXRC_USE_LOCALE)
- str = wxGetTranslation(str);
+ str = wxGetTranslation(str, m_resource->GetDomain());
strList.Add(str);
return NULL;
// add to the list
wxString str = GetNodeContent(m_node);
if (m_resource->GetFlags() & wxXRC_USE_LOCALE)
- str = wxGetTranslation(str);
+ str = wxGetTranslation(str, m_resource->GetDomain());
strList.Add(str);
return NULL;
// add to the list
wxString str = GetNodeContent(m_node);
if (m_resource->GetFlags() & wxXRC_USE_LOCALE)
- str = wxGetTranslation(str);
+ str = wxGetTranslation(str, m_resource->GetDomain());
strList.Add(str);
return NULL;
if (m_resource->GetFlags() & wxXRC_USE_LOCALE)
{
- str = wxGetTranslation(str);
+ str = wxGetTranslation(str, m_resource->GetDomain());
if ( !tooltip.empty() )
- tooltip = wxGetTranslation(tooltip);
+ tooltip = wxGetTranslation(tooltip, m_resource->GetDomain());
if ( hasHelptext )
- helptext = wxGetTranslation(helptext);
+ helptext = wxGetTranslation(helptext, m_resource->GetDomain());
}
labels.push_back(str);
return old;
}
-wxXmlResource::wxXmlResource(int flags)
+wxXmlResource::wxXmlResource(int flags, const wxString& domain)
{
m_flags = flags;
m_version = -1;
+ m_domain = NULL;
+ if (! domain.empty() )
+ SetDomain(domain);
}
-wxXmlResource::wxXmlResource(const wxString& filemask, int flags)
+wxXmlResource::wxXmlResource(const wxString& filemask, int flags, const wxString& domain)
{
m_flags = flags;
m_version = -1;
+ m_domain = NULL;
+ if (! domain.empty() )
+ SetDomain(domain);
Load(filemask);
}
wxXmlResource::~wxXmlResource()
{
+ if (m_domain)
+ free(m_domain);
ClearHandlers();
}
+void wxXmlResource::SetDomain(const wxChar* domain)
+{
+ if (m_domain)
+ free(m_domain);
+ m_domain = NULL;
+ if (domain && wxStrlen(domain))
+ m_domain = wxStrdup(domain);
+}
+
/* static */
wxString wxXmlResource::ConvertFileNameToURL(const wxString& filename)
if (translate && parNode &&
parNode->GetPropVal(wxT("translate"), wxEmptyString) != wxT("0"))
{
- return wxGetTranslation(str2);
+ return wxGetTranslation(str2, m_resource->GetDomain());
}
else
{
};
+//---------------------------------------------------------------------------
+
+%{
+class wxPyLocale : public wxLocale
+{
+public:
+ wxPyLocale();
+
+ wxPyLocale(const wxChar *szName, // name (for messages)
+ const wxChar *szShort = (const wxChar *) NULL, // dir prefix (for msg files)
+ const wxChar *szLocale = (const wxChar *) NULL, // 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 wxChar *GetString(const wxChar *szOrigString,
+ const wxChar *szDomain = NULL) const;
+ virtual const wxChar *GetString(const wxChar *szOrigString,
+ const wxChar *szOrigString2, size_t n,
+ const wxChar *szDomain = NULL) const;
+
+ virtual wxChar *GetSingularString(const wxChar *szOrigString,
+ const wxChar *szDomain = NULL) const;
+ virtual wxChar *GetPluralString(const wxChar *szOrigString,
+ const wxChar *szOrigString2, size_t n,
+ const wxChar *szDomain = NULL) const;
+
+ PYPRIVATE;
+private:
+ DECLARE_NO_COPY_CLASS(wxPyLocale)
+};
+
+wxPyLocale::wxPyLocale() : wxLocale()
+{
+}
+
+wxPyLocale::wxPyLocale(const wxChar *szName, // name (for messages)
+ const wxChar *szShort, // dir prefix (for msg files)
+ const wxChar *szLocale, // locale (for setlocale)
+ bool bLoadDefault, // preload wxstd.mo?
+ bool bConvertEncoding) // convert Win<->Unix if necessary?
+ : wxLocale(szName, szShort, szLocale, bLoadDefault, bConvertEncoding)
+{
+}
+
+wxPyLocale::wxPyLocale(int language, // wxLanguage id or custom language
+ int flags) : wxLocale(language, flags)
+{
+}
+
+wxPyLocale::~wxPyLocale()
+{
+}
+
+const wxChar *wxPyLocale::GetString(const wxChar *szOrigString,
+ const wxChar *szDomain) const
+{
+ wxChar *str = GetSingularString(szOrigString, szDomain);
+ return (str != NULL) ? str : wxLocale::GetString(szOrigString, szDomain);
+}
+
+const wxChar *wxPyLocale::GetString(const wxChar *szOrigString,
+ const wxChar *szOrigString2, size_t n,
+ const wxChar *szDomain) const
+{
+ wxChar *str = GetPluralString(szOrigString, szOrigString2, n, szDomain);
+ return (str != NULL) ? str : wxLocale::GetString(szOrigString, szOrigString2, n, szDomain);
+}
+
+wxChar *wxPyLocale::GetSingularString(const wxChar *szOrigString,
+ const wxChar *szDomain) const
+{
+ bool found;
+ static wxString str;
+ 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.
+ wxPyBlock_t blocked = wxPyBeginBlockThreads();
+ if((found=wxPyCBH_findCallback(m_myInst, "GetSingularString"))) {
+ PyObject* param1 = wx2PyString(szOrigString);
+ PyObject* param2 = wx2PyString(szDomain);
+ 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 ? (wxChar*)str.c_str() : NULL);
+}
+wxChar *wxPyLocale::GetPluralString(const wxChar *szOrigString,
+ const wxChar *szOrigString2, size_t n,
+ const wxChar *szDomain) const
+{
+ bool found;
+ static wxString str;
+ 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.
+ wxPyBlock_t blocked = wxPyBeginBlockThreads();
+ if((found=wxPyCBH_findCallback(m_myInst, "GetPluralString"))) {
+ PyObject* param1 = wx2PyString(szOrigString);
+ PyObject* param2 = wx2PyString(szOrigString2);
+ PyObject* param4 = wx2PyString(szDomain);
+ 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 ? (wxChar*)str.c_str() : NULL);
+}
+%}
+
+
+class wxPyLocale : public wxLocale
+{
+public:
+ %pythonAppend wxPyLocale "self._setCallbackInfo(self, 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 wxChar *GetSingularString(const wxChar *szOrigString,
+ const wxChar *szDomain = NULL) const;
+ virtual const wxChar *GetPluralString(const wxChar *szOrigString,
+ const wxChar *szOrigString2, size_t n,
+ const wxChar *szDomain = NULL) 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& 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
{
public:
- %pythonAppend wxXmlResource(const wxString& filemask, int flags) "self.InitAllHandlers()"
- %pythonAppend wxXmlResource(int flags) "val.InitAllHandlers()"
+ %pythonAppend wxXmlResource(const wxString& filemask, int flags,
+ const wxString& domain=wxEmptyString) "self.InitAllHandlers()"
+ %pythonAppend wxXmlResource(int flags,
+ const wxString& domain=wxEmptyString) "val.InitAllHandlers()"
// Ctors.
// Flags: wxXRC_USE_LOCALE
// wxXRC_NO_SUBCLASSING
// subclass property of object nodes will be ignored
// (useful for previews in XRC editors)
- wxXmlResource(const wxString& filemask, int flags = wxXRC_USE_LOCALE);
- %RenameCtor(EmptyXmlResource, wxXmlResource(int flags = wxXRC_USE_LOCALE));
+ wxXmlResource(const wxString& filemask, int flags = wxXRC_USE_LOCALE,
+ const wxString& domain=wxEmptyString);
+ %RenameCtor(EmptyXmlResource, wxXmlResource(int flags = wxXRC_USE_LOCALE,
+ const wxString& domain=wxEmptyString));
+
~wxXmlResource();
// Set flags after construction.
void SetFlags(int flags) { m_flags = flags; }
+ // Get/Set the domain to be passed to the translation functions, defaults to NULL.
+ wxString GetDomain() const;
+ void SetDomain(const wxString& domain);
};
//----------------------------------------------------------------------