]>
git.saurik.com Git - wxWidgets.git/blob - samples/internat/internat.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Demonstrates internationalisation (i18n) support
4 // Author: Vadim Zeitlin/Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx/wx.h".
21 #include "wx/wxprec.h"
35 #if defined(__WXGTK__) || defined(__WXX11__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXMGL__)
36 #include "mondrian.xpm"
39 // ----------------------------------------------------------------------------
41 // ----------------------------------------------------------------------------
43 // Define a new application type
44 class MyApp
: public wxApp
47 virtual bool OnInit();
50 wxLocale m_locale
; // locale we'll be using
53 // Define a new frame type
54 class MyFrame
: public wxFrame
57 MyFrame(wxLocale
& m_locale
);
60 void OnQuit(wxCommandEvent
& event
);
61 void OnAbout(wxCommandEvent
& event
);
62 void OnPlay(wxCommandEvent
& event
);
63 void OnOpen(wxCommandEvent
& event
);
70 // ----------------------------------------------------------------------------
72 // ----------------------------------------------------------------------------
74 // ID for the menu commands
83 // ----------------------------------------------------------------------------
85 // ----------------------------------------------------------------------------
87 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
88 EVT_MENU(INTERNAT_QUIT
, MyFrame::OnQuit
)
89 EVT_MENU(wxID_ABOUT
, MyFrame::OnAbout
)
90 EVT_MENU(INTERNAT_TEST
, MyFrame::OnPlay
)
91 EVT_MENU(INTERNAT_OPEN
, MyFrame::OnOpen
)
96 // ============================================================================
98 // ============================================================================
100 // ----------------------------------------------------------------------------
102 // ----------------------------------------------------------------------------
104 // `Main program' equivalent, creating windows and returning main app frame
111 // the parameter must be the lang index
112 wxString
tmp(argv
[1]);
116 static const wxLanguage langIds
[] =
122 wxLANGUAGE_BULGARIAN
,
128 wxLANGUAGE_ENGLISH_US
133 // note that it makes no sense to translate these strings, they are
134 // shown before we set the locale anyhow
135 const wxString langNames
[] =
137 _T("System default"),
150 // the arrays should be in sync
151 wxCOMPILE_TIME_ASSERT( WXSIZEOF(langNames
) == WXSIZEOF(langIds
),
152 LangArraysMismatch
);
154 lng
= wxGetSingleChoiceIndex
156 _T("Please choose language:"),
164 m_locale
.Init(langIds
[lng
]);
167 // Initialize the catalogs we'll be using
168 m_locale
.AddCatalog(wxT("internat"));
170 // this catalog is installed in standard location on Linux systems and
171 // shows that you may make use of the standard message catalogs as well
173 // if it's not installed on your system, it is just silently ignored
177 m_locale
.AddCatalog(_T("fileutils"));
181 // Create the main frame window
182 MyFrame
*frame
= new MyFrame(m_locale
);
185 frame
->SetIcon(wxICON(mondrian
));
188 wxMenu
*file_menu
= new wxMenu
;
189 file_menu
->Append(wxID_ABOUT
, _("&About..."));
190 file_menu
->AppendSeparator();
191 file_menu
->Append(INTERNAT_QUIT
, _("E&xit"));
193 wxMenu
*test_menu
= new wxMenu
;
194 test_menu
->Append(INTERNAT_OPEN
, _("&Open bogus file"));
195 test_menu
->Append(INTERNAT_TEST
, _("&Play a game"));
197 wxMenuBar
*menu_bar
= new wxMenuBar
;
198 menu_bar
->Append(file_menu
, _("&File"));
199 menu_bar
->Append(test_menu
, _("&Test"));
200 frame
->SetMenuBar(menu_bar
);
209 // ----------------------------------------------------------------------------
211 // ----------------------------------------------------------------------------
213 // main frame constructor
214 MyFrame::MyFrame(wxLocale
& locale
)
217 _("International wxWindows App"),
225 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
) )
230 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
233 wxString locale
= m_locale
.GetLocale();
234 wxString sysname
= m_locale
.GetSysName();
235 wxString canname
= m_locale
.GetCanonicalName();
237 localeInfo
.Printf(_("Language: %s\nSystem locale name: %s\nCanonical locale name: %s\n"),
238 locale
.c_str(), sysname
.c_str(), canname
.c_str() );
243 wxString(_("I18n sample\n(c) 1998, 1999 Vadim Zeitlin and Julian Smart"))
247 wxOK
| wxICON_INFORMATION
251 void MyFrame::OnPlay(wxCommandEvent
& WXUNUSED(event
))
253 wxString str
= wxGetTextFromUser
255 _("Enter your number:"),
256 _("Try to guess my number!"),
268 if ( !str
.ToLong(&num
) || num
< 0 )
270 str
= _("You've probably entered an invalid number.");
274 // this message is not translated (not in catalog) because we used _T()
275 // and not _() around it
276 str
= _T("You've found a bug in this program!");
278 else if ( num
== 17 )
282 // string must be split in two -- otherwise the translation would't be
284 str
<< _("Congratulations! you've won. Here is the magic phrase:")
285 << _("cannot create fifo `%s'");
289 // this is a more implicit way to write _() but note that if you use it
290 // you must ensure that the strings get extracted in the message
291 // catalog as by default xgettext won't do it (it only knows of _(),
292 // not wxGetTranslation())
293 str
= wxGetTranslation(_T("Bad luck! try again..."));
296 wxMessageBox(str
, _("Result"), wxOK
| wxICON_INFORMATION
);
299 void MyFrame::OnOpen(wxCommandEvent
&)
301 // open a bogus file -- the error message should be also translated if you've
302 // got wxstd.mo somewhere in the search path
303 wxFile
file(wxT("NOTEXIST.ING"));