Install gettext-0.18.1.1.tar.gz
[msysgit.git] / mingw / share / doc / gettext / examples / hello-c++-wxwidgets / hello.cc
blob47191c79dbce56d68faec2067be26060d083bd71
1 // Example for use of GNU gettext.
2 // This file is in the public domain.
4 // Source code of the C++ program.
6 #include <wx/wx.h>
7 #include <wx/intl.h>
9 /* Get getpid() declaration. */
10 #if HAVE_UNISTD_H
11 # include <unistd.h>
12 #endif
14 class MyApp: public wxApp
16 public:
17 virtual bool OnInit();
18 private:
19 // wxWidgets has the concept of a "current locale". It is the one returned
20 // by wxGetLocale() and implicitly used by wxGetTranslation.
21 // But there is no way to explicitly set this current locale! Rather, it is
22 // always set to the last constructed locale(!), and is modified when a
23 // locale is destroyed. In such a way that the current locale points to
24 // invalid memory after you do
25 // wxLocale *a = new wxLocale;
26 // wxLocale *b = new wxLocale;
27 // delete a;
28 // delete b;
29 // So, to avoid problems, we use exactly one instance of wxLocale, and keep
30 // it alive for the entire application lifetime.
31 wxLocale appLocale;
34 class MyFrame: public wxFrame
36 public:
37 MyFrame();
40 // This defines the main() function.
41 IMPLEMENT_APP(MyApp)
43 bool MyApp::OnInit()
45 // First, register the base directory where to look up .mo files.
46 wxLocale::AddCatalogLookupPathPrefix(wxT(LOCALEDIR));
47 // Second, initialize the locale and set the application-wide message domain.
48 appLocale.Init();
49 appLocale.AddCatalog(wxT("hello-c++-wxwidgets"));
50 // Now wxGetLocale() is initialized appropriately.
52 // Then only start building the GUI elements of the application.
54 // Create the main frame window.
55 MyFrame *frame = new MyFrame();
57 // Show the frame.
58 frame->Show(true);
59 SetTopWindow(frame);
61 return true;
64 MyFrame::MyFrame()
65 : wxFrame(NULL, wxID_ANY, _T("Hello example"))
67 wxStaticText *label1 =
68 new wxStaticText(this, wxID_ANY, _("Hello, world!"));
70 wxString label2text =
71 wxString::Format(_("This program is running as process number %d."),
72 getpid());
73 wxStaticText *label2 =
74 new wxStaticText(this, wxID_ANY, label2text);
76 wxBoxSizer *topSizer = new wxBoxSizer(wxVERTICAL);
77 topSizer->Add(label1);
78 topSizer->Add(label2);
79 SetSizer(topSizer);