Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wxTranslations::AddCatalog() returns false for msgid language if it's different from system language #24019

Closed
taler21 opened this issue Oct 30, 2023 · 2 comments
Labels
regression Worked previously, doesn't work any longer
Milestone

Comments

@taler21
Copy link
Contributor

taler21 commented Oct 30, 2023

In wxWidgets-3.2.3 there is a regression that was introduced with commit d178223.

wxTranslations::AddCatalog() now returns false if the selected language:

  • is that of the "msgid" strings in source code AND
  • is different to the system language AND
  • has no available catalog (which is perfectly fine for the msgid language)

This issue can be reproduced in the internat sample with the following modifications:

diff --git "a/samples/internat/internat.cpp" "b/samples/internat/internat.cpp"
index 53ca7ebbb1..d575fccc93 100644
--- "a/samples/internat/internat.cpp"
+++ "b/samples/internat/internat.cpp"
@@ -212,6 +212,14 @@ bool MyApp::OnInit()
         langDesc = langInfo ? langInfo->Description
                             : wxString("the default system language");
 
+    const wxLanguage msgIdLang = wxLANGUAGE_ENGLISH_US;
+
+    const wxLanguageInfo* const
+            msgIdLangInfo = wxUILocale::GetLanguageInfo( msgIdLang );
+    const wxString
+            msgIdLangDesc = msgIdLangInfo ? msgIdLangInfo->Description
+                                          : wxString("the msgid language");
+/*
     if ( m_setLocale == Locale_Ask )
     {
         m_setLocale = wxMessageBox
@@ -227,7 +235,7 @@ bool MyApp::OnInit()
     }
 
     if ( m_setLocale == Locale_Set )
-    {
+*/  {
         if ( !wxUILocale::UseDefault() )
         {
             wxLogWarning("Failed to initialize the default system locale.");
@@ -245,13 +253,14 @@ bool MyApp::OnInit()
 
         // Create the object for message translation and set it up for global use.
         wxTranslations* const trans = new wxTranslations();
+        trans->SetLanguage( msgIdLang );
         wxTranslations::Set(trans);
 
         // Initialize the catalogs we'll be using.
-        if ( !trans->AddCatalog("internat") )
+        if ( !trans->AddCatalog("internat", msgIdLang ) )
         {
             wxLogError(_("Couldn't find/load 'internat' catalog for %s."),
-                       langDesc);
+                       msgIdLangDesc);
         }
 
         // Now try to add wxstd.mo so that loading "NOTEXIST.ING" file will produce

Platform and version information

  • wxWidgets version you use: 3.2.3
  • wxWidgets port you use: wxMSW
  • OS and its version: Windows 10
@vadz vadz added the regression Worked previously, doesn't work any longer label Nov 2, 2023
@vadz vadz added this to the 3.2.4 milestone Nov 2, 2023
vadz added a commit to vadz/wxWidgets that referenced this issue Nov 5, 2023
When the original messages language matches the language of the locale
being used, these strings can be used directly and so AddCatalog()
should still return true for them but it didn't do it any more after the
changes of 94b1a17 (Add AddAvailableCatalog() and use it in
AddStdCatalog(), 2023-09-30).

See wxWidgets#18227.

Closes wxWidgets#24019.
@vadz
Copy link
Contributor

vadz commented Nov 5, 2023

Thanks for noticing and reporting this (and sorry for breaking it)!

I believe the fix is to avoid checking the languages available on the current system entirely when the language to use is explicitly specified (i.e. when not using wxLANGUAGE_DEFAULT), which is what #24037 does now. Could you please let me know if applying this to 3.2 fixes the problem for you? TIA!

@taler21
Copy link
Contributor Author

taler21 commented Nov 7, 2023

Yes, that fixes the issue. Thanks!

@vadz vadz closed this as completed in 39079cb Nov 7, 2023
vadz added a commit that referenced this issue Nov 7, 2023
When the original messages language matches the language of the locale
being used, these strings can be used directly and so AddCatalog()
should still return true for them but it didn't do it any more after the
changes of 94b1a17 (Add AddAvailableCatalog() and use it in
AddStdCatalog(), 2023-09-30).

See #18227.

Closes #24019.

Closes #24037.

(cherry picked from commit 39079cb)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
regression Worked previously, doesn't work any longer
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants