]>
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 and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation
17 // For compilers that support precompilation, includes "wx/wx.h".
18 #include "wx/wxprec.h"
32 #if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__)
33 #include "mondrian.xpm"
36 // Define a new application type
37 class MyApp
: public wxApp
40 virtual bool OnInit();
43 wxLocale m_locale
; // locale we'll be using
46 // Define a new frame type
47 class MyFrame
: public wxFrame
50 MyFrame(wxFrame
*frame
, const char *title
, int x
, int y
, int w
, int h
,
54 void OnQuit(wxCommandEvent
& event
);
55 void OnAbout(wxCommandEvent
& event
);
56 void OnPlay(wxCommandEvent
& event
);
57 void OnOpen(wxCommandEvent
& event
);
64 // ID for the menu commands
74 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
75 EVT_MENU(MINIMAL_QUIT
, MyFrame::OnQuit
)
76 EVT_MENU(MINIMAL_ABOUT
, MyFrame::OnAbout
)
77 EVT_MENU(MINIMAL_TEST
, MyFrame::OnPlay
)
78 EVT_MENU(MINIMAL_OPEN
, MyFrame::OnOpen
)
84 // `Main program' equivalent, creating windows and returning main app frame
87 const wxString langs
[] =
89 _T("(System default)"),
97 SetExitOnFrameDelete(FALSE
);
98 int lng
= wxGetSingleChoiceIndex(_T("Please choose language:"), _T("Language"),
99 WXSIZEOF(langs
), langs
);
100 SetExitOnFrameDelete(TRUE
);
104 case 0 : m_locale
.Init(wxLANGUAGE_DEFAULT
); break;
105 case 1 : m_locale
.Init(wxLANGUAGE_FRENCH
); break;
106 case 2 : m_locale
.Init(wxLANGUAGE_GERMAN
); break;
107 case 3 : m_locale
.Init(wxLANGUAGE_RUSSIAN
); break;
108 case 4 : m_locale
.Init(wxLANGUAGE_ENGLISH
); break;
110 case 5 : m_locale
.Init(wxLANGUAGE_ENGLISH_US
); break;
113 // Initialize the catalogs we'll be using
114 /* not needed any more, done in wxLocale ctor
115 m_locale.AddCatalog("wxstd"); // 1) for library messages
117 m_locale
.AddCatalog("internat"); // 2) our private one
118 /* this catalog is installed in standard location on Linux systems,
119 it might not be installed on yours - just ignore the errrors
120 or comment out this line then */
124 m_locale
.AddCatalog("fileutils"); // 3) and another just for testing
128 // Create the main frame window
129 MyFrame
*frame
= new MyFrame((wxFrame
*) NULL
, _("International wxWindows App"),
130 50, 50, 350, 60, m_locale
);
133 frame
->SetIcon(wxICON(mondrian
));
136 wxMenu
*file_menu
= new wxMenu
;
137 file_menu
->Append(MINIMAL_ABOUT
, _("&About..."));
138 file_menu
->AppendSeparator();
139 file_menu
->Append(MINIMAL_QUIT
, _("E&xit"));
141 wxMenu
*test_menu
= new wxMenu
;
142 test_menu
->Append(MINIMAL_OPEN
, _("&Open bogus file"));
143 test_menu
->Append(MINIMAL_TEST
, _("&Play a game"));
145 wxMenuBar
*menu_bar
= new wxMenuBar
;
146 menu_bar
->Append(file_menu
, _("&File"));
147 menu_bar
->Append(test_menu
, _("&Test"));
148 frame
->SetMenuBar(menu_bar
);
157 // My frame constructor
158 MyFrame::MyFrame(wxFrame
*frame
, const char *title
, int x
, int y
, int w
, int h
,
160 : wxFrame(frame
, -1, title
, wxPoint(x
, y
), wxSize(w
, h
)),
165 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
) )
170 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
173 localeInfo
.Printf(_("Language: %s\n"
174 "System locale name: %s\n"
175 "Canonical locale name: %s\n"),
176 m_locale
.GetLocale(),
177 m_locale
.GetSysName().c_str(),
178 m_locale
.GetCanonicalName().c_str());
180 wxMessageDialog(this, wxString(_("I18n sample\n"
181 "(c) 1998, 1999 Vadim Zeitlin and Julian Smart"))
182 + wxT("\n\n") + localeInfo
,
183 _("About Internat"), wxOK
| wxICON_INFORMATION
).ShowModal();
186 void MyFrame::OnPlay(wxCommandEvent
& WXUNUSED(event
))
188 wxString str
= wxGetTextFromUser(_("Enter your number:"),
189 _("Try to guess my number!"),
195 sscanf(str
, "%d", &num
);
197 str
= _("You've probably entered an invalid number.");
198 else if ( num
== 9 ) // this message is not translated (not in catalog)
199 str
= "You've found a bug in this program!";
200 else if ( num
!= 17 ) // a more implicit way to write _()
201 str
= wxGetTranslation("Bad luck! try again...");
204 // string must be split in two -- otherwise the translation won't be found
205 str
<< _("Congratulations! you've won. Here is the magic phrase:")
206 << _("cannot create fifo `%s'");
209 wxMessageBox(str
, _("Result"), wxOK
| wxICON_INFORMATION
);
212 void MyFrame::OnOpen(wxCommandEvent
&)
214 // open a bogus file -- the error message should be also translated if you've
215 // got wxstd.mo somewhere in the search path
216 wxFile
file("NOTEXIST.ING");