-void MyFrame::OnPlay(wxCommandEvent& event)
-{
- wxString str = wxGetTextFromUser(_("Enter your number:"),
- _("Try to guess my number!"),
- "", this);
- int num;
- sscanf(str, "%d", &num);
- if ( num == 0 )
- str = _("you've probably entered an invalid number.");
- else if ( num == 9 ) // this message is not translated (not in catalog)
- str = _("you've found a bug in this program!");
- else if ( num != 17 ) // a more implicit way to write _()
- str = wxGetTranslation("bad luck! try again...");
- else {
- str.Empty();
- // string must be split in two -- otherwise the translation won't be found
- str << _("congratulations! you've won. Here is the magic phrase:")
- << _("cannot create fifo `%s'");
- }
-
- wxMessageBox(str, _("Result"), wxOK | wxICON_INFORMATION);
+void MyFrame::OnTestLocaleAvail(wxCommandEvent& WXUNUSED(event))
+{
+ static wxString s_locale;
+ wxString locale = wxGetTextFromUser
+ (
+ _("Enter the locale to test"),
+ wxGetTextFromUserPromptStr,
+ s_locale,
+ this
+ );
+ if ( locale.empty() )
+ return;
+
+ s_locale = locale;
+ const wxLanguageInfo * const info = wxLocale::FindLanguageInfo(s_locale);
+ if ( !info )
+ {
+ wxLogError(_("Locale \"%s\" is unknown."), s_locale.c_str());
+ return;
+ }
+
+ if ( wxLocale::IsAvailable(info->Language) )
+ wxLogMessage(_("Locale \"%s\" is available."), s_locale.c_str());
+ else
+ wxLogWarning(_("Locale \"%s\" is not available."), s_locale.c_str());
+}
+
+void MyFrame::OnOpen(wxCommandEvent& WXUNUSED(event))
+{
+ // open a bogus file -- the error message should be also translated if
+ // you've got wxstd.mo somewhere in the search path (see MyApp::OnInit)
+ wxFile file("NOTEXIST.ING");
+}
+
+void MyFrame::OnTest1(wxCommandEvent& WXUNUSED(event))
+{
+ const wxString& title = _("Testing _() (gettext)");
+
+ // NOTE: using the wxTRANSLATE() macro here we won't show a localized
+ // string in the text entry dialog; we'll simply show the un-translated
+ // string; however if the user press "ok" without altering the text,
+ // since the "default value" string has been extracted by xgettext
+ // the wxGetTranslation call later will manage to return a localized
+ // string
+ wxTextEntryDialog d(this, _("Please enter text to translate"),
+ title, wxTRANSLATE("default value"));
+
+ if (d.ShowModal() == wxID_OK)
+ {
+ wxString v = d.GetValue();
+ wxString s(title);
+ s << "\n" << v << " -> "
+ << wxGetTranslation(v.c_str()) << "\n";
+ wxMessageBox(s);
+ }
+}
+
+void MyFrame::OnTest2(wxCommandEvent& WXUNUSED(event))
+{
+ const wxString& title = _("Testing _N() (ngettext)");
+ wxTextEntryDialog d(this,
+ _("Please enter range for plural forms of \"n files deleted\" phrase"),
+ title, "0-10");
+
+ if (d.ShowModal() == wxID_OK)
+ {
+ int first, last;
+ wxSscanf(d.GetValue(), "%d-%d", &first, &last);
+ wxString s(title);
+ s << "\n";
+ for (int n = first; n <= last; ++n)
+ {
+ s << n << " " <<
+ wxPLURAL("file deleted", "files deleted", n) <<
+ "\n";
+ }
+ wxMessageBox(s);
+ }