Merge branch 'i18n-context'
Closes https://github.com/wxWidgets/wxWidgets/pull/530
This commit is contained in:
@@ -35,10 +35,19 @@
|
||||
// --keyword="_" --keyword="wxPLURAL:1,2" options
|
||||
// to extract the strings from the sources)
|
||||
#ifndef WXINTL_NO_GETTEXT_MACRO
|
||||
#define _(s) wxGetTranslation((s))
|
||||
#define wxPLURAL(sing, plur, n) wxGetTranslation((sing), (plur), n)
|
||||
#define _(s) wxGetTranslation((s))
|
||||
#define wxPLURAL(sing, plur, n) wxGetTranslation((sing), (plur), n)
|
||||
#endif
|
||||
|
||||
// wx-specific macro for translating strings in the given context: if you use
|
||||
// them, you need to also add
|
||||
// --keyword="wxGETTEXT_IN_CONTEXT:1c,2" --keyword="wxGETTEXT_IN_CONTEXT_PLURAL:1c,2,3"
|
||||
// options to xgettext invocation.
|
||||
#define wxGETTEXT_IN_CONTEXT(c, s) \
|
||||
wxGetTranslation((s), wxString(), c)
|
||||
#define wxGETTEXT_IN_CONTEXT_PLURAL(c, sing, plur, n) \
|
||||
wxGetTranslation((sing), (plur), n, wxString(), c)
|
||||
|
||||
// another one which just marks the strings for extraction, but doesn't
|
||||
// perform the translation (use -kwxTRANSLATE with xgettext!)
|
||||
#define wxTRANSLATE(str) str
|
||||
@@ -79,7 +88,7 @@ public:
|
||||
wxString GetDomain() const { return m_domain; }
|
||||
|
||||
// get the translated string: returns NULL if not found
|
||||
const wxString *GetString(const wxString& sz, unsigned n = UINT_MAX) const;
|
||||
const wxString *GetString(const wxString& sz, unsigned n = UINT_MAX, const wxString& ct = wxEmptyString) const;
|
||||
|
||||
protected:
|
||||
wxMsgCatalog(const wxString& domain)
|
||||
@@ -154,10 +163,12 @@ public:
|
||||
|
||||
// access to translations
|
||||
const wxString *GetTranslatedString(const wxString& origString,
|
||||
const wxString& domain = wxEmptyString) const;
|
||||
const wxString& domain = wxEmptyString,
|
||||
const wxString& context = wxEmptyString) const;
|
||||
const wxString *GetTranslatedString(const wxString& origString,
|
||||
unsigned n,
|
||||
const wxString& domain = wxEmptyString) const;
|
||||
const wxString& domain = wxEmptyString,
|
||||
const wxString& context = wxEmptyString) const;
|
||||
|
||||
wxString GetHeaderValue(const wxString& header,
|
||||
const wxString& domain = wxEmptyString) const;
|
||||
@@ -247,10 +258,11 @@ protected:
|
||||
|
||||
// get the translation of the string in the current locale
|
||||
inline const wxString& wxGetTranslation(const wxString& str,
|
||||
const wxString& domain = wxString())
|
||||
const wxString& domain = wxString(),
|
||||
const wxString& context = wxString())
|
||||
{
|
||||
wxTranslations *trans = wxTranslations::Get();
|
||||
const wxString *transStr = trans ? trans->GetTranslatedString(str, domain)
|
||||
const wxString *transStr = trans ? trans->GetTranslatedString(str, domain, context)
|
||||
: NULL;
|
||||
if ( transStr )
|
||||
return *transStr;
|
||||
@@ -263,10 +275,11 @@ inline const wxString& wxGetTranslation(const wxString& str,
|
||||
inline const wxString& wxGetTranslation(const wxString& str1,
|
||||
const wxString& str2,
|
||||
unsigned n,
|
||||
const wxString& domain = wxString())
|
||||
const wxString& domain = wxString(),
|
||||
const wxString& context = wxString())
|
||||
{
|
||||
wxTranslations *trans = wxTranslations::Get();
|
||||
const wxString *transStr = trans ? trans->GetTranslatedString(str1, n, domain)
|
||||
const wxString *transStr = trans ? trans->GetTranslatedString(str1, n, domain, context)
|
||||
: NULL;
|
||||
if ( transStr )
|
||||
return *transStr;
|
||||
@@ -287,6 +300,8 @@ inline const wxString& wxGetTranslation(const wxString& str1,
|
||||
#define _(s) (s)
|
||||
#endif
|
||||
#define wxPLURAL(sing, plur, n) ((n) == 1 ? (sing) : (plur))
|
||||
#define wxGETTEXT_IN_CONTEXT(c, s) (s)
|
||||
#define wxGETTEXT_IN_CONTEXT_PLURAL(c, sing, plur, n) wxPLURAL(sing, plur, n)
|
||||
#endif
|
||||
|
||||
#define wxTRANSLATE(str) str
|
||||
@@ -304,6 +319,10 @@ template<typename TString, typename TDomain>
|
||||
inline TString wxGetTranslation(TString str, TDomain WXUNUSED(domain))
|
||||
{ return str; }
|
||||
|
||||
template<typename TString, typename TDomain, typename TContext>
|
||||
inline TString wxGetTranslation(TString str, TDomain WXUNUSED(domain), TContext WXUNUSED(context))
|
||||
{ return str; }
|
||||
|
||||
template<typename TString, typename TDomain>
|
||||
inline TString wxGetTranslation(TString str1, TString str2, size_t n)
|
||||
{ return n == 1 ? str1 : str2; }
|
||||
@@ -313,6 +332,12 @@ inline TString wxGetTranslation(TString str1, TString str2, size_t n,
|
||||
TDomain WXUNUSED(domain))
|
||||
{ return n == 1 ? str1 : str2; }
|
||||
|
||||
template<typename TString, typename TDomain, typename TContext>
|
||||
inline TString wxGetTranslation(TString str1, TString str2, size_t n,
|
||||
TDomain WXUNUSED(domain),
|
||||
TContext WXUNUSED(context))
|
||||
{ return n == 1 ? str1 : str2; }
|
||||
|
||||
#endif // wxUSE_INTL/!wxUSE_INTL
|
||||
|
||||
// define this one just in case it occurs somewhere (instead of preferred
|
||||
|
Reference in New Issue
Block a user