From a71b3d2cd6c6f2dc03cf3f02d52f38155495f998 Mon Sep 17 00:00:00 2001 From: redtide Date: Tue, 15 Jun 2021 07:34:34 +0200 Subject: [PATCH 1/4] Update the standard catalog name used in the internat sample What used to be called "fileutils" is called "coreutils" since many years now, so use it to demonstrate loading of the standard catalog. Closes https://github.com/wxWidgets/wxWidgets/pull/2395 --- samples/internat/internat.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/internat/internat.cpp b/samples/internat/internat.cpp index 16e86a6620..3d04895800 100644 --- a/samples/internat/internat.cpp +++ b/samples/internat/internat.cpp @@ -268,7 +268,7 @@ bool MyApp::OnInit() #ifdef __LINUX__ { wxLogNull noLog; - m_locale.AddCatalog("fileutils"); + m_locale.AddCatalog("coreutils"); } #endif From bef4ccede4938a1a66df0509e9ec8b0038b294af Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 15 Jun 2021 14:32:44 +0200 Subject: [PATCH 2/4] Remove unnecessary wxLogNull from internat sample There is no need to suppress wxLog messages from AddCatalog() because it doesn't log any errors even if the catalog is not found, while tracing messages (given only if WXTRACE is set) from it can be useful. --- samples/internat/internat.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/samples/internat/internat.cpp b/samples/internat/internat.cpp index 3d04895800..7b4e7465c8 100644 --- a/samples/internat/internat.cpp +++ b/samples/internat/internat.cpp @@ -266,10 +266,7 @@ bool MyApp::OnInit() // // if it's not installed on your system, it is just silently ignored #ifdef __LINUX__ - { - wxLogNull noLog; - m_locale.AddCatalog("coreutils"); - } + m_locale.AddCatalog("coreutils"); #endif // Create the main frame window From c880cf98728591d50162eee19d3a561f7359c0d4 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 15 Jun 2021 14:42:48 +0200 Subject: [PATCH 3/4] Test for USE_COREUTILS_MO in the internat sample This is more clear than testing for Linux and will allow enabling this code under other systems later (as there doesn't seem to be any real reason not to do it under other Unix systems too). No real changes. --- samples/internat/internat.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/samples/internat/internat.cpp b/samples/internat/internat.cpp index 7b4e7465c8..c08ba35294 100644 --- a/samples/internat/internat.cpp +++ b/samples/internat/internat.cpp @@ -38,6 +38,12 @@ #include "../sample.xpm" #endif +// Under Linux we demonstrate loading an existing message catalog using +// coreutils package (which is always installed) as an example. +#ifdef __LINUX__ + #define USE_COREUTILS_MO +#endif // __LINUX__ + // ---------------------------------------------------------------------------- // private classes // ---------------------------------------------------------------------------- @@ -265,9 +271,9 @@ bool MyApp::OnInit() // shows that you may make use of the standard message catalogs as well // // if it's not installed on your system, it is just silently ignored -#ifdef __LINUX__ +#ifdef USE_COREUTILS_MO m_locale.AddCatalog("coreutils"); -#endif +#endif // USE_COREUTILS_MO // Create the main frame window MyFrame *frame = new MyFrame(m_locale); From aabfa8806b6b30458ef37d6ab42ee9c551436c2f Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 15 Jun 2021 14:43:38 +0200 Subject: [PATCH 4/4] Show translation from coreutils message catalog string Actually test using the coreutils catalog, as this was broken for many years due to using a wrong catalog name and not adding /usr/share/locale as a search prefix, but went unnoticed. So add a menu item to show translation of a string in this catalog to make testing that this works simpler. --- samples/internat/internat.cpp | 37 ++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/samples/internat/internat.cpp b/samples/internat/internat.cpp index c08ba35294..5502619b53 100644 --- a/samples/internat/internat.cpp +++ b/samples/internat/internat.cpp @@ -42,6 +42,7 @@ // coreutils package (which is always installed) as an example. #ifdef __LINUX__ #define USE_COREUTILS_MO + static bool g_loadedCoreutilsMO = false; #endif // __LINUX__ // ---------------------------------------------------------------------------- @@ -72,6 +73,9 @@ public: public: void OnTestLocaleAvail(wxCommandEvent& event); void OnAbout(wxCommandEvent& event); +#ifdef USE_COREUTILS_MO + void OnCoreutilsHelp(wxCommandEvent& event); +#endif // USE_COREUTILS_MO void OnQuit(wxCommandEvent& event); void OnPlay(wxCommandEvent& event); @@ -170,6 +174,9 @@ wxCOMPILE_TIME_ASSERT( WXSIZEOF(langNames) == WXSIZEOF(langIds), wxBEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_MENU(INTERNAT_TEST, MyFrame::OnTestLocaleAvail) EVT_MENU(wxID_ABOUT, MyFrame::OnAbout) +#ifdef USE_COREUTILS_MO + EVT_MENU(wxID_HELP, MyFrame::OnCoreutilsHelp) +#endif // USE_COREUTILS_MO EVT_MENU(wxID_EXIT, MyFrame::OnQuit) EVT_MENU(INTERNAT_PLAY, MyFrame::OnPlay) @@ -272,7 +279,8 @@ bool MyApp::OnInit() // // if it's not installed on your system, it is just silently ignored #ifdef USE_COREUTILS_MO - m_locale.AddCatalog("coreutils"); + wxLocale::AddCatalogLookupPathPrefix("/usr/share/locale"); + g_loadedCoreutilsMO = m_locale.AddCatalog("coreutils"); #endif // USE_COREUTILS_MO // Create the main frame window @@ -330,6 +338,10 @@ MyFrame::MyFrame(wxLocale& locale) macro_menu->Append(INTERNAT_MACRO_9, wxGETTEXT_IN_CONTEXT_PLURAL("context_2", "sing", "plur", 2)); wxMenu *help_menu = new wxMenu; +#ifdef USE_COREUTILS_MO + help_menu->Append(wxID_HELP, _("Show coreutils &help")); + help_menu->AppendSeparator(); +#endif // USE_COREUTILS_MO help_menu->Append(wxID_ABOUT, _("&About")); wxMenuBar *menu_bar = new wxMenuBar; @@ -383,6 +395,29 @@ void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) dlg.ShowModal(); } +#ifdef USE_COREUTILS_MO + +void MyFrame::OnCoreutilsHelp(wxCommandEvent& WXUNUSED(event)) +{ + if ( g_loadedCoreutilsMO ) + { + // Try showing translation of a message used by coreutils: notice that + // this string isn't inside _(), as its translation is supposed to be + // already present in the coreutils catalog, we don't need to extract + // it from here. + const char* const msg = " --help display this help and exit\n"; + wxLogMessage("Translation of coreutils help option description is:\n%s", + wxGetTranslation(msg)); + } + else + { + wxLogMessage("Loading coreutils message catalog failed, set " + "WXTRACE=i18n to get more information about it."); + } +} + +#endif // USE_COREUTILS_MO + void MyFrame::OnPlay(wxCommandEvent& WXUNUSED(event)) { wxString str = wxGetTextFromUser