- wxString str = wxGetTextFromUser(_("Enter your number:"),
- _("Try to guess my number!"),
- "", this);
- if ( str.IsEmpty() )
- return;
-
- int num;
- wxSscanf(str, wxT("%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(wxT("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);
+ wxString str = wxGetTextFromUser
+ (
+ _("Enter your number:"),
+ _("Try to guess my number!"),
+ wxEmptyString,
+ this
+ );
+
+ if ( str.empty() )
+ {
+ // cancelled
+ return;
+ }
+
+ long num;
+ if ( !str.ToLong(&num) || num < 0 )
+ {
+ str = _("You've probably entered an invalid number.");
+ }
+ else if ( num == 9 )
+ {
+ // this message is not translated (not in catalog) because we used _T()
+ // and not _() around it
+ str = _T("You've found a bug in this program!");
+ }
+ else if ( num == 17 )
+ {
+ str.clear();
+
+ // string must be split in two -- otherwise the translation would't be
+ // found
+ str << _("Congratulations! you've won. Here is the magic phrase:")
+ << _("cannot create fifo `%s'");
+ }
+ else
+ {
+ // this is a more implicit way to write _() but note that if you use it
+ // you must ensure that the strings get extracted in the message
+ // catalog as by default xgettext won't do it (it only knows of _(),
+ // not wxGetTranslation())
+ str = wxGetTranslation(_T("Bad luck! try again..."));
+ }
+
+ 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());