diff --git a/include/wx/translation.h b/include/wx/translation.h index 9c6e42d32db7..1ea68f660615 100644 --- a/include/wx/translation.h +++ b/include/wx/translation.h @@ -333,43 +333,53 @@ inline const wxString& wxGetTranslation(const char *str1, wxString(context, conv)); } - #define wxTRANS_INPUT_STR(s) wxASCII_STR(s) -#else +// We can't construct wxString implicitly in this case, so use a helper. +inline wxString wxTRANS_INPUT_STR(const char* s) +{ + return wxString::FromAscii(s); +} + +inline wxString wxTRANS_INPUT_STR(const wchar_t* s) +{ + return wxString(s); +} +#else // !wxNO_IMPLICIT_WXSTRING_ENCODING + // We can rely on implicit conversion, so don't bother with the helper. #define wxTRANS_INPUT_STR(s) s #endif // wxNO_IMPLICIT_WXSTRING_ENCODING namespace wxTransImplStrict { -// Wrapper functions that only accept string literals as arguments, -// not variables, not char* pointers. -template -const wxString& wxUnderscoreWrapper(const char (&msg)[N]) +// Wrapper functions that only accept string literals (regular or wide) as +// arguments, not variables, not char* pointers, not wchar_t* pointers. +template +const wxString& wxUnderscoreWrapper(const T (&msg)[N]) { return wxGetTranslation(wxTRANS_INPUT_STR(msg)); } -template -const wxString& wxPluralWrapper(const char (&msg)[M], - const char (&plural)[N], +template +const wxString& wxPluralWrapper(const T (&msg)[M], + const T (&plural)[N], int count) { return wxGetTranslation(wxTRANS_INPUT_STR(msg), wxTRANS_INPUT_STR(plural), count); } -template -const wxString& wxGettextInContextWrapper(const char (&ctx)[M], - const char (&msg)[N]) +template +const wxString& wxGettextInContextWrapper(const T (&ctx)[M], + const T (&msg)[N]) { return wxGetTranslation(wxTRANS_INPUT_STR(msg), wxString(), wxTRANS_INPUT_STR(ctx)); } -template -const wxString& wxGettextInContextPluralWrapper(const char (&ctx)[L], - const char (&msg)[M], - const char (&plural)[N], +template +const wxString& wxGettextInContextPluralWrapper(const T (&ctx)[L], + const T (&msg)[M], + const T (&plural)[N], int count) { return wxGetTranslation(wxTRANS_INPUT_STR(msg), wxTRANS_INPUT_STR(plural), diff --git a/tests/allheaders.cpp b/tests/allheaders.cpp index b59e4cd91f7b..4cec55633d03 100644 --- a/tests/allheaders.cpp +++ b/tests/allheaders.cpp @@ -421,4 +421,10 @@ TEST_CASE("wxNO_IMPLICIT_WXSTRING_ENCODING", "[string]") wxPLURAL("singular", "plural", 2); wxGETTEXT_IN_CONTEXT("context", "text"); wxGETTEXT_IN_CONTEXT_PLURAL("context", "singular", "plural", 3); + + // Also wide strings can be used: + _(L"item"); + wxGETTEXT_IN_CONTEXT(L"context", L"item"); + wxPLURAL(L"sing", L"plur", 3); + wxGETTEXT_IN_CONTEXT_PLURAL(L"context", L"sing", L"plur", 3); }