]>
git.saurik.com Git - wxWidgets.git/blob - samples/internat/internat.cpp
40d065e6741b8ad5b7233f890ab1dd5ca804ea28
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__)
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
);
53 void OnQuit(wxCommandEvent
& event
);
54 void OnAbout(wxCommandEvent
& event
);
55 void OnPlay(wxCommandEvent
& event
);
56 void OnOpen(wxCommandEvent
& event
);
57 bool OnClose(void) { return TRUE
; }
62 // ID for the menu commands
72 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
73 EVT_MENU(MINIMAL_QUIT
, MyFrame::OnQuit
)
74 EVT_MENU(MINIMAL_ABOUT
, MyFrame::OnAbout
)
75 EVT_MENU(MINIMAL_TEST
, MyFrame::OnPlay
)
76 EVT_MENU(MINIMAL_OPEN
, MyFrame::OnOpen
)
82 // `Main program' equivalent, creating windows and returning main app frame
83 bool MyApp::OnInit(void)
85 // Initialize the catalogs we'll be using
86 m_locale
.Init("french", "fr", "C");
88 /* not needed any more, done in wxLocale ctor
89 m_locale.AddCatalog("wxstd"); // 1) for library messages
91 m_locale
.AddCatalog("internat"); // 2) our private one
92 /* this catalog is installed in standard location on Linux systems,
93 it might not be installed on yours - just ignore the errrors
94 or comment out this line then */
95 m_locale
.AddCatalog("fileutils"); // 3) and another just for testing
97 // Create the main frame window
98 MyFrame
*frame
= new MyFrame((wxFrame
*) NULL
, _("International wxWindows App"), 50, 50, 150, 40);
101 frame
->SetIcon(wxICON(mondrian
));
104 wxMenu
*file_menu
= new wxMenu
;
105 file_menu
->Append(MINIMAL_ABOUT
, _("&About"));
106 file_menu
->AppendSeparator();
107 file_menu
->Append(MINIMAL_QUIT
, _("E&xit"));
109 wxMenu
*test_menu
= new wxMenu
;
110 test_menu
->Append(MINIMAL_OPEN
, _("&Open bogus file"));
111 test_menu
->Append(MINIMAL_TEST
, _("&Play a game"));
113 wxMenuBar
*menu_bar
= new wxMenuBar
;
114 menu_bar
->Append(file_menu
, _("&File"));
115 menu_bar
->Append(test_menu
, _("&Test"));
116 frame
->SetMenuBar(menu_bar
);
125 // My frame constructor
126 MyFrame::MyFrame(wxFrame
*frame
, const char *title
, int x
, int y
, int w
, int h
)
127 : wxFrame(frame
, -1, title
, wxPoint(x
, y
), wxSize(w
, h
))
131 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
) )
136 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
138 wxMessageDialog(this, _("I18n sample\n© Vadim Zeitlin & Julian Smart"),
139 _("About Internat"), wxOK
| wxICON_INFORMATION
).ShowModal();
142 void MyFrame::OnPlay(wxCommandEvent
& WXUNUSED(event
))
144 wxString str
= wxGetTextFromUser(_("Enter your number:"),
145 _("Try to guess my number!"),
148 sscanf(str
, "%d", &num
);
150 str
= _("you've probably entered an invalid number.");
151 else if ( num
== 9 ) // this message is not translated (not in catalog)
152 str
= _("you've found a bug in this program!");
153 else if ( num
!= 17 ) // a more implicit way to write _()
154 str
= wxGetTranslation("bad luck! try again...");
157 // string must be split in two -- otherwise the translation won't be found
158 str
<< _("congratulations! you've won. Here is the magic phrase:")
159 << _("cannot create fifo `%s'");
162 wxMessageBox(str
, _("Result"), wxOK
| wxICON_INFORMATION
);
165 void MyFrame::OnOpen(wxCommandEvent
&)
167 // open a bogus file -- the error message should be also translated if you've
168 // got wxstd.mo somewhere in the search path
169 wxFile
file("NOTEXIST.ING");