X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/45e6e6f8ab806b337dffeb3b52fec7eba3c845ef..f1d5aa4eca541a2f90044a63f555985d6bd4adf3:/samples/internat/internat.cpp diff --git a/samples/internat/internat.cpp b/samples/internat/internat.cpp index 7a91d37e08..a9d2233b4d 100644 --- a/samples/internat/internat.cpp +++ b/samples/internat/internat.cpp @@ -25,12 +25,13 @@ #endif #ifndef WX_PRECOMP -#include "wx/wx.h" + #include "wx/wx.h" #endif #include "wx/intl.h" #include "wx/file.h" #include "wx/log.h" +#include "wx/cmdline.h" #if defined(__WXGTK__) || defined(__WXX11__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXMGL__) #include "mondrian.xpm" @@ -44,10 +45,15 @@ class MyApp: public wxApp { public: + MyApp() { m_lang = wxLANGUAGE_UNKNOWN; } + + virtual void OnInitCmdLine(wxCmdLineParser& parser); + virtual bool OnCmdLineParsed(wxCmdLineParser& parser); virtual bool OnInit(); protected: - wxLocale m_locale; // locale we'll be using + wxLanguage m_lang; // language specified by user + wxLocale m_locale; // locale we'll be using }; // Define a new frame type @@ -163,40 +169,64 @@ IMPLEMENT_APP(MyApp) // MyApp // ---------------------------------------------------------------------------- -// `Main program' equivalent, creating windows and returning main app frame -bool MyApp::OnInit() +// command line arguments handling +void MyApp::OnInitCmdLine(wxCmdLineParser& parser) { - if ( !wxApp::OnInit() ) - return false; + parser.AddParam(_("locale"), + wxCMD_LINE_VAL_STRING, + wxCMD_LINE_PARAM_OPTIONAL); + + wxApp::OnInitCmdLine(parser); +} - long lng = -1; +bool MyApp::OnCmdLineParsed(wxCmdLineParser& parser) +{ + if ( !wxApp::OnCmdLineParsed(parser) ) + return false; - if ( argc == 2 ) + if ( parser.GetParamCount() ) { - // the parameter must be the lang index - wxString tmp(argv[1]); - tmp.ToLong(&lng); + const wxString loc = parser.GetParam(); + const wxLanguageInfo * const lang = wxLocale::FindLanguageInfo(loc); + if ( !lang ) + { + wxLogError(_("Locale \"%s\" is unknown."), loc); + return false; + } + + m_lang = wx_static_cast(wxLanguage, lang->Language); } - if ( lng == -1 ) + return true; +} + +// `Main program' equivalent, creating windows and returning main app frame +bool MyApp::OnInit() +{ + if ( !wxApp::OnInit() ) + return false; + + if ( m_lang == wxLANGUAGE_UNKNOWN ) { - lng = wxGetSingleChoiceIndex - ( - _T("Please choose language:"), - _T("Language"), - WXSIZEOF(langNames), - langNames - ); + int lng = wxGetSingleChoiceIndex + ( + _("Please choose language:"), + _("Language"), + WXSIZEOF(langNames), + langNames + ); + m_lang = lng == -1 ? wxLANGUAGE_DEFAULT : langIds[lng]; } - if ( lng != -1 ) + if ( m_lang != wxLANGUAGE_DEFAULT ) { // don't use wxLOCALE_LOAD_DEFAULT flag so that Init() doesn't return // false just because it failed to load wxstd catalog - if ( !m_locale.Init(langIds[lng], wxLOCALE_CONV_ENCODING) ) + if ( !m_locale.Init(m_lang, wxLOCALE_CONV_ENCODING) ) { - wxLogError(_T("This language is not supported by the system.")); - return false; + wxLogWarning(_("This language is not supported by the system.")); + + // continue nevertheless } } @@ -384,7 +414,7 @@ void MyFrame::OnOpen(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnTest1(wxCommandEvent& WXUNUSED(event)) { - const wxChar* title = _("Testing _() (gettext)"); + const wxString title = _("Testing _() (gettext)"); wxTextEntryDialog d(this, _("Please enter text to translate"), title, wxTRANSLATE("default value")); if (d.ShowModal() == wxID_OK) @@ -399,7 +429,7 @@ void MyFrame::OnTest1(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnTest2(wxCommandEvent& WXUNUSED(event)) { - const wxChar* title = _("Testing _N() (ngettext)"); + const wxString title = _("Testing _N() (ngettext)"); wxTextEntryDialog d(this, _("Please enter range for plural forms of \"n files deleted\" phrase"), title, _T("0-10")); @@ -421,7 +451,7 @@ void MyFrame::OnTest2(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnTest3(wxCommandEvent& WXUNUSED(event)) { - const wxChar* lines[] = + const char* lines[] = { wxTRANSLATE("line 1"), wxTRANSLATE("line 2"),