From a47b560fd457c93858be3404d036ac0a0dc03cf3 Mon Sep 17 00:00:00 2001 From: Lauri Nurmi Date: Tue, 29 Oct 2024 00:40:47 +0200 Subject: [PATCH] Fix wxGETTEXT_IN_CONTEXT* with wxNO_IMPLICIT_WXSTRING_ENCODING The call to wxGetTranslation() was ambiguous. Fix this by adding missing wxASCII_STR() for all string literal arguments in wxGETTEXT_IN_CONTEXT and wxGETTEXT_IN_CONTEXT_PLURAL, just as it is used in _(). Also test that all translation macros expand to compilable code when wxNO_IMPLICIT_WXSTRING_ENCODING is enabled. See #1312 and also #24916. Closes #24925. --- include/wx/translation.h | 4 ++-- tests/allheaders.cpp | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/include/wx/translation.h b/include/wx/translation.h index aaa55571d4..8f465279c7 100644 --- a/include/wx/translation.h +++ b/include/wx/translation.h @@ -62,10 +62,10 @@ using wxTranslationsHashMap = std::unordered_map; wxGetTranslation((s), wxString(), c) #else #define wxGETTEXT_IN_CONTEXT(c, s) \ - wxGetTranslation(wxASCII_STR(s), wxString(), c) + wxGetTranslation(wxASCII_STR(s), wxString(), wxASCII_STR(c)) #endif #define wxGETTEXT_IN_CONTEXT_PLURAL(c, sing, plur, n) \ - wxGetTranslation((sing), (plur), n, wxString(), c) + wxGetTranslation(wxASCII_STR(sing), wxASCII_STR(plur), n, wxString(), wxASCII_STR(c)) // another one which just marks the strings for extraction, but doesn't // perform the translation (use -kwxTRANSLATE with xgettext!) diff --git a/tests/allheaders.cpp b/tests/allheaders.cpp index 5b5527f455..b59e4cd91f 100644 --- a/tests/allheaders.cpp +++ b/tests/allheaders.cpp @@ -413,4 +413,12 @@ TEST_CASE("wxNO_IMPLICIT_WXSTRING_ENCODING", "[string]") #endif wxLogSysError(wxASCII_STR("Bogus error for testing")); + + // Check that all translation macros expand to compilable + // code also when wxNO_IMPLICIT_WXSTRING_ENCODING is enabled. + + _("some text"); + wxPLURAL("singular", "plural", 2); + wxGETTEXT_IN_CONTEXT("context", "text"); + wxGETTEXT_IN_CONTEXT_PLURAL("context", "singular", "plural", 3); }