diff --git a/include/wx/translation.h b/include/wx/translation.h index 88a7ba6430..fcde4c7863 100644 --- a/include/wx/translation.h +++ b/include/wx/translation.h @@ -300,6 +300,42 @@ inline const wxString& wxGetTranslation(const wxString& str1, : 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 // the macros should still be defined - otherwise compilation would fail diff --git a/src/common/translation.cpp b/src/common/translation.cpp index ee8b586fa0..c6c8991367 100644 --- a/src/common/translation.cpp +++ b/src/common/translation.cpp @@ -2110,4 +2110,16 @@ public: 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