]>
git.saurik.com Git - wxWidgets.git/blob - samples/internat/internat.cpp
265dd57e678767a068a317f4ec1327b1dead2e97
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 // Define a new application type
33 class MyApp
: public wxApp
38 virtual bool OnInit();
41 wxLocale m_locale
; // locale we'll be using
44 // Define a new frame type
45 class MyFrame
: public wxFrame
48 MyFrame(wxFrame
*frame
, const char *title
, int x
, int y
, int w
, int h
);
51 void OnQuit(wxCommandEvent
& event
);
52 void OnAbout(wxCommandEvent
& event
);
53 void OnPlay(wxCommandEvent
& event
);
54 void OnOpen(wxCommandEvent
& event
);
55 bool OnClose(void) { return TRUE
; }
60 // ID for the menu commands
70 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
71 EVT_MENU(MINIMAL_QUIT
, MyFrame::OnQuit
)
72 EVT_MENU(MINIMAL_ABOUT
, MyFrame::OnAbout
)
73 EVT_MENU(MINIMAL_TEST
, MyFrame::OnPlay
)
74 EVT_MENU(MINIMAL_OPEN
, MyFrame::OnOpen
)
80 MyApp::MyApp() : m_locale("french", "fr", "C")
82 // catalogs we'll be using:
83 /* not needed any more, done in wxLocale ctor
84 m_locale.AddCatalog("wxstd"); // 1) for library messages
86 m_locale
.AddCatalog("internat"); // 2) our private one
87 /* this catalog is installed in standard location on Linux systems,
88 it might not be installed on yours - just ignore the errrors
89 or comment out this line then */
90 m_locale
.AddCatalog("fileutils"); // 3) and another just for testing
94 // `Main program' equivalent, creating windows and returning main app frame
95 bool MyApp::OnInit(void)
97 // Create the main frame window
98 MyFrame
*frame
= new MyFrame(NULL
, _("Minimal wxWindows App"), 50, 50, 150, 40);
102 frame
->SetIcon(wxIcon("mondrian"));
105 frame
->SetIcon(wxIcon("aiai.xbm"));
109 wxMenu
*file_menu
= new wxMenu
;
110 file_menu
->Append(MINIMAL_ABOUT
, _("&About"));
111 file_menu
->AppendSeparator();
112 file_menu
->Append(MINIMAL_QUIT
, _("E&xit"));
114 wxMenu
*test_menu
= new wxMenu
;
115 test_menu
->Append(MINIMAL_OPEN
, _("&Open bogus file"));
116 test_menu
->Append(MINIMAL_TEST
, _("&Play a game"));
118 wxMenuBar
*menu_bar
= new wxMenuBar
;
119 menu_bar
->Append(file_menu
, _("&File"));
120 menu_bar
->Append(test_menu
, _("&Test"));
121 frame
->SetMenuBar(menu_bar
);
130 // My frame constructor
131 MyFrame::MyFrame(wxFrame
*frame
, const char *title
, int x
, int y
, int w
, int h
)
132 : wxFrame(frame
, -1, title
, wxPoint(x
, y
), wxSize(w
, h
))
136 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
) )
141 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
143 wxMessageDialog(this, _("I18n sample\n© Vadim Zeitlin & Julian Smart"),
144 _("About Internat"), wxOK
| wxICON_INFORMATION
).ShowModal();
147 void MyFrame::OnPlay(wxCommandEvent
& WXUNUSED(event
))
149 wxString str
= wxGetTextFromUser(_("Enter your number:"),
150 _("Try to guess my number!"),
153 sscanf(str
, "%d", &num
);
155 str
= _("you've probably entered an invalid number.");
156 else if ( num
== 9 ) // this message is not translated (not in catalog)
157 str
= _("you've found a bug in this program!");
158 else if ( num
!= 17 ) // a more implicit way to write _()
159 str
= wxGetTranslation("bad luck! try again...");
162 // string must be split in two -- otherwise the translation won't be found
163 str
<< _("congratulations! you've won. Here is the magic phrase:")
164 << _("cannot create fifo `%s'");
167 wxMessageBox(str
, _("Result"), wxOK
| wxICON_INFORMATION
);
170 void MyFrame::OnOpen(wxCommandEvent
&)
172 // open a bogus file -- the error message should be also translated if you've
173 // got wxstd.mo somewhere in the search path
174 wxFile
file("NOTEXIST.ING");