Replace GetString(), which always returns something (possibly the
original string) with GetTranslatedString() that returns either a
pointer to translated string or NULL.
This simplifies the code a bit, all handling of missing translations is
now done in wxGetTranslation().
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@74836
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
bool IsLoaded(const wxString& domain) const;
// access to translations
bool IsLoaded(const wxString& domain) const;
// access to translations
- const wxString& GetString(const wxString& origString,
- const wxString& domain = wxEmptyString) const;
- const wxString& GetString(const wxString& origString,
- const wxString& origString2,
- unsigned n,
- const wxString& domain = wxEmptyString) const;
+ const wxString *GetTranslatedString(const wxString& origString,
+ const wxString& domain = wxEmptyString) const;
+ const wxString *GetTranslatedString(const wxString& origString,
+ unsigned n,
+ const wxString& domain = wxEmptyString) const;
wxString GetHeaderValue(const wxString& header,
const wxString& domain = wxEmptyString) const;
wxString GetHeaderValue(const wxString& header,
const wxString& domain = wxEmptyString) const;
// get the translation of the string in the current locale
inline const wxString& wxGetTranslation(const wxString& str,
// get the translation of the string in the current locale
inline const wxString& wxGetTranslation(const wxString& str,
- const wxString& domain = wxEmptyString)
+ const wxString& domain = wxString())
{
wxTranslations *trans = wxTranslations::Get();
{
wxTranslations *trans = wxTranslations::Get();
- if ( trans )
- return trans->GetString(str, domain);
+ const wxString *transStr = trans ? trans->GetTranslatedString(str, domain)
+ : NULL;
+ if ( transStr )
+ return *transStr;
else
// NB: this function returns reference to a string, so we have to keep
// a copy of it somewhere
else
// NB: this function returns reference to a string, so we have to keep
// a copy of it somewhere
inline const wxString& wxGetTranslation(const wxString& str1,
const wxString& str2,
unsigned n,
inline const wxString& wxGetTranslation(const wxString& str1,
const wxString& str2,
unsigned n,
- const wxString& domain = wxEmptyString)
+ const wxString& domain = wxString())
{
wxTranslations *trans = wxTranslations::Get();
{
wxTranslations *trans = wxTranslations::Get();
- if ( trans )
- return trans->GetString(str1, str2, n, domain);
+ const wxString *transStr = trans ? trans->GetTranslatedString(str1, n, domain)
+ : NULL;
+ if ( transStr )
+ return *transStr;
else
// NB: this function returns reference to a string, so we have to keep
// a copy of it somewhere
else
// NB: this function returns reference to a string, so we have to keep
// a copy of it somewhere
const wxString& GetName() const;
/**
const wxString& GetName() const;
/**
- Calls wxTranslations::GetString(const wxString&, const wxString&) const.
+ Calls wxGetTranslation(const wxString&, const wxString&).
*/
virtual const wxString& GetString(const wxString& origString,
const wxString& domain = wxEmptyString) const;
/**
*/
virtual const wxString& GetString(const wxString& origString,
const wxString& domain = wxEmptyString) const;
/**
- Calls wxTranslations::GetString(const wxString&, const wxString&, unsigned, const wxString&) const.
+ Calls wxGetTranslation(const wxString&, const wxString&, unsigned, const wxString&).
*/
virtual const wxString& GetString(const wxString& origString,
const wxString& origString2, unsigned n,
*/
virtual const wxString& GetString(const wxString& origString,
const wxString& origString2, unsigned n,
Retrieves the translation for a string in all loaded domains unless the @a domain
parameter is specified (and then only this catalog/domain is searched).
Retrieves the translation for a string in all loaded domains unless the @a domain
parameter is specified (and then only this catalog/domain is searched).
- Returns original string if translation is not available (in this case an
- error message is generated the first time a string is not found; use
- wxLogNull to suppress it).
+ Returns @NULL if translation is not available.
This function is thread-safe.
@remarks Domains are searched in the last to first order, i.e. catalogs
added later override those added before.
This function is thread-safe.
@remarks Domains are searched in the last to first order, i.e. catalogs
added later override those added before.
- const wxString& GetString(const wxString& origString,
- const wxString& domain = wxEmptyString) const;
+ const wxString *GetTranslatedString(const wxString& origString,
+ const wxString& domain = wxEmptyString) const;
/**
Retrieves the translation for a string in all loaded domains unless the @a domain
parameter is specified (and then only this catalog/domain is searched).
/**
Retrieves the translation for a string in all loaded domains unless the @a domain
parameter is specified (and then only this catalog/domain is searched).
- Returns original string if translation is not available (in this case an
- error message is generated the first time a string is not found; use
- wxLogNull to suppress it).
+ Returns @NULL if translation is not available.
This form is used when retrieving translation of string that has different
singular and plural form in English or different plural forms in some
other language.
This form is used when retrieving translation of string that has different
singular and plural form in English or different plural forms in some
other language.
- It takes two extra arguments: @a origString parameter must contain the
- singular form of the string to be converted.
-
- It is also used as the key for the search in the catalog.
- The @a origString2 parameter is the plural form (in English).
- The parameter @a n is used to determine the plural form.
- If no message catalog is found @a origString is returned if 'n == 1',
- otherwise @a origString2.
+ @param origString The singular form of the string to be converted.
+ @param n The number on which the plural form choice depends on.
+ (In some languages, there are different plural forms
+ for e.g. n=2 and n=3 etc., in addition to the singlular
+ form (n=1) being different.)
See GNU gettext manual for additional information on plural forms handling.
This method is called by the wxGetTranslation() function and _() macro.
See GNU gettext manual for additional information on plural forms handling.
This method is called by the wxGetTranslation() function and _() macro.
@remarks Domains are searched in the last to first order, i.e. catalogs
added later override those added before.
@remarks Domains are searched in the last to first order, i.e. catalogs
added later override those added before.
- const wxString& GetString(const wxString& origString,
- const wxString& origString2,
- unsigned n,
- const wxString& domain = wxEmptyString) const;
+ const wxString *GetTranslatedString(const wxString& origString,
+ unsigned n,
+ const wxString& domain = wxEmptyString) const;
/**
Returns the header value for header @a header.
/**
Returns the header value for header @a header.
provided: the _() macro is defined to do the same thing as
wxGetTranslation().
provided: the _() macro is defined to do the same thing as
wxGetTranslation().
- This function calls wxTranslations::GetString().
-
This function is thread-safe.
@note This function is not suitable for literal strings in Unicode builds
This function is thread-safe.
@note This function is not suitable for literal strings in Unicode builds
<http://www.gnu.org/software/gettext/manual/gettext.html#Plural-forms>
For a shorter alternative see the wxPLURAL() macro.
<http://www.gnu.org/software/gettext/manual/gettext.html#Plural-forms>
For a shorter alternative see the wxPLURAL() macro.
- This function calls wxTranslation::GetString().
-
This function is thread-safe.
@header{wx/intl.h}
This function is thread-safe.
@header{wx/intl.h}
-const wxString& wxTranslations::GetString(const wxString& origString,
- const wxString& domain) const
+const wxString *wxTranslations::GetTranslatedString(const wxString& origString,
+ const wxString& domain) const
- return GetString(origString, origString, UINT_MAX, domain);
+ return GetTranslatedString(origString, UINT_MAX, domain);
-const wxString& wxTranslations::GetString(const wxString& origString,
- const wxString& origString2,
- unsigned n,
- const wxString& domain) const
+const wxString *wxTranslations::GetTranslatedString(const wxString& origString,
+ unsigned n,
+ const wxString& domain) const
{
if ( origString.empty() )
{
if ( origString.empty() )
- return GetUntranslatedString(origString);
const wxString *trans = NULL;
wxMsgCatalog *pMsgCat;
const wxString *trans = NULL;
wxMsgCatalog *pMsgCat;
(!domain.empty() ? wxString::Format("domain '%s' ", domain) : wxString()),
m_lang
);
(!domain.empty() ? wxString::Format("domain '%s' ", domain) : wxString()),
m_lang
);
-
- if (n == UINT_MAX)
- return GetUntranslatedString(origString);
- else
- return GetUntranslatedString(n == 1 ? origString : origString2);