Explicit encoding for implicit conversion in wxGetTranslation()

This commit is contained in:
Arrigo Marchiori
2019-10-23 11:21:00 +02:00
committed by Vadim Zeitlin
parent c86bcf962d
commit 860f6076b8
2 changed files with 48 additions and 0 deletions

View File

@@ -300,6 +300,42 @@ inline const wxString& wxGetTranslation(const wxString& str1,
: wxTranslations::GetUntranslatedString(str2); : wxTranslations::GetUntranslatedString(str2);
} }
/*
* Get and set the default encoding for strings to be translated.
* These are only useful when the wxNO_IMPLICIT_WXSTRING_ENCODING macro is
* defined.
*/
WXDLLIMPEXP_BASE const wxMBConv &wxGetInlineEncoding();
WXDLLIMPEXP_BASE void wxSetInlineEncoding(const wxMBConv &conv);
#ifdef wxNO_IMPLICIT_WXSTRING_ENCODING
/*
* It must always be possible to call wxGetTranslation() with const
* char* arguments.
*/
inline const wxString& wxGetTranslation(const char *str,
const char *domain = "",
const char *context = "") {
const wxMBConv &conv = wxGetInlineEncoding();
return wxGetTranslation(wxString(str, conv), wxString(domain, conv),
wxString(context, conv));
}
inline const wxString& wxGetTranslation(const char *str1,
const char *str2,
unsigned n,
const char *domain = "",
const char *context = "") {
const wxMBConv &conv = wxGetInlineEncoding();
return wxGetTranslation(wxString(str1, conv), wxString(str2, conv), n,
wxString(domain, conv),
wxString(context, conv));
}
#endif // wxNO_IMPLICIT_WXSTRING_ENCODING
#else // !wxUSE_INTL #else // !wxUSE_INTL
// the macros should still be defined - otherwise compilation would fail // the macros should still be defined - otherwise compilation would fail

View File

@@ -2110,4 +2110,16 @@ public:
wxIMPLEMENT_DYNAMIC_CLASS(wxTranslationsModule, wxModule); wxIMPLEMENT_DYNAMIC_CLASS(wxTranslationsModule, wxModule);
// Encoding for strings to be translated, passed as const char *.
static const wxMBConv *inlineEncoding = &wxConvLibc;
WXDLLIMPEXP_BASE const wxMBConv &wxGetInlineEncoding() {
return *inlineEncoding;
}
WXDLLIMPEXP_BASE void wxSetInlineEncoding(const wxMBConv &conv) {
inlineEncoding = &conv;
}
#endif // wxUSE_INTL #endif // wxUSE_INTL