]> git.saurik.com Git - wxWidgets.git/commitdiff
translate wxMessageDialog labels to the language of the current locale (closes #10962)
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 5 Jul 2009 11:48:01 +0000 (11:48 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 5 Jul 2009 11:48:01 +0000 (11:48 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@61319 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/changes.txt
samples/internat/internat.cpp
src/msw/msgdlg.cpp

index be69b64869e8e5ceccfdbee811e5e5452090c93c..caedfce93e3cf6f01e06dc1ec65f2b73b0673062 100644 (file)
@@ -371,6 +371,7 @@ GTK:
 
 MSW:
 
+- Translate wxMessageDialog labels to the language of the current locale.
 - Allow changing the height of wxChoice and wxComboBox.
 - Update CRT environment block in wxSetEnv() too.
 - Fix wxMDIChildFrame::SetSize() (Lars Rosenboom).
index 1647630af4d4ba16df080c771572bc972d52cae8..cc00ea8e0351a03965c4257b5f199d983145b041 100644 (file)
@@ -76,6 +76,7 @@ public:
     void OnTest1(wxCommandEvent& event);
     void OnTest2(wxCommandEvent& event);
     void OnTest3(wxCommandEvent& event);
+    void OnTestMsgBox(wxCommandEvent& event);
 
     DECLARE_EVENT_TABLE()
 
@@ -93,7 +94,8 @@ enum
     INTERNAT_PLAY,
     INTERNAT_TEST_1,
     INTERNAT_TEST_2,
-    INTERNAT_TEST_3
+    INTERNAT_TEST_3,
+    INTERNAT_TEST_MSGBOX
 };
 
 // language data
@@ -163,6 +165,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
     EVT_MENU(INTERNAT_TEST_1, MyFrame::OnTest1)
     EVT_MENU(INTERNAT_TEST_2, MyFrame::OnTest2)
     EVT_MENU(INTERNAT_TEST_3, MyFrame::OnTest3)
+    EVT_MENU(INTERNAT_TEST_MSGBOX, MyFrame::OnTestMsgBox)
 END_EVENT_TABLE()
 
 IMPLEMENT_APP(MyApp)
@@ -302,6 +305,8 @@ MyFrame::MyFrame(wxLocale& locale)
     test_menu->Append(INTERNAT_TEST_1, _("&1 _() (gettext)"), _("Tests the _() macro"));
     test_menu->Append(INTERNAT_TEST_2, _("&2 _N() (ngettext)"), _("Tests the _N() macro"));
     test_menu->Append(INTERNAT_TEST_3, _("&3 wxTRANSLATE() (gettext_noop)"), _("Tests the wxTRANSLATE() macro"));
+    test_menu->Append(INTERNAT_TEST_MSGBOX, _("&Message box test"),
+                      _("Tests message box buttons labels translation"));
 
     wxMenuBar *menu_bar = new wxMenuBar;
     menu_bar->Append(file_menu, _("&File"));
@@ -498,4 +503,17 @@ void MyFrame::OnTest3(wxCommandEvent& WXUNUSED(event))
     wxMessageBox(s);
 }
 
-
+void MyFrame::OnTestMsgBox(wxCommandEvent& WXUNUSED(event))
+{
+    if ( wxMessageBox
+         (
+            _("Are the labels of the buttons in this message box "
+              "translated into the current locale language?"),
+            _("wxWidgets i18n sample"),
+            wxYES_NO,
+            this
+         ) != wxYES )
+    {
+        wxMessageBox(_("Please report the details of your platform to us."));
+    }
+}
index 6166b125a45b39c73ba59ba3ac0a7d4543cc5668..829b4a855e008b321436849616b2dfd19c386a25 100644 (file)
@@ -30,6 +30,7 @@
 
 #ifndef WX_PRECOMP
     #include "wx/app.h"
+    #include "wx/intl.h"
     #include "wx/utils.h"
     #include "wx/dialog.h"
     #if wxUSE_MSGBOX_HOOK
@@ -445,6 +446,34 @@ int wxMessageDialog::ShowModal()
         m_parent = GetParentForModalDialog();
     HWND hWnd = m_parent ? GetHwndOf(m_parent) : NULL;
 
+#if wxUSE_INTL
+    // native message box always uses the current user locale but the program
+    // may be using a different one and in this case we need to manually
+    // translate the button labels to avoid mismatch between the language of
+    // the message box text and its buttons
+    wxLocale * const loc = wxGetLocale();
+    if ( loc && loc->GetLanguage() != wxLocale::GetSystemLanguage() )
+    {
+        if ( m_dialogStyle & wxYES_NO )
+        {
+            // use the strings with mnemonics here as the native message box
+            // does
+            SetYesNoLabels(_("&Yes"), _("&No"));
+        }
+
+        // we may or not have the Ok/Cancel buttons but either we do have them
+        // or we already made the labels custom because we called
+        // SetYesNoLabels() above so doing this does no harm -- and is
+        // necessary in wxYES_NO | wxCANCEL case
+        //
+        // note that we don't use mnemonics here for consistency with the
+        // native message box (which probably doesn't use them because
+        // Enter/Esc keys can be already used to dismiss the message box
+        // using keyboard)
+        SetOKCancelLabels(_("OK"), _("Cancel"));
+    }
+#endif // wxUSE_INTL
+
     // translate wx style in MSW
     unsigned int msStyle;
     const long wxStyle = GetMessageDialogStyle();