8. Internationalization
Sooner or later you are confronted with users asking for localized version of your application, at least if it's successful. So it is better plan to implement international support right from the beginning.
8.1 Language support
The base for any language support is to mark each text a user ever sees for translation even if you don't plan or provide any. This gives your users a chance to start their own translation which might flow back to you. When you use text in your application immediately decide if a user ever will see it or not.
There are three different kind of text:
- Text a user sees and has to interpret. This is the most common case of text in an application. This text has to be marked for translation.
- Text which is a name or a common notion. Never translate names unless there is a common translation of it. Text that is used only internally in your application and a user normally doesn't see (like debug information's). This text should not be translated but marked for multi byte support.
- Text has to be plain ASCII. This almost only the case for text which is used in the internal program flow (i.e. filenames).
Mark text for translation with the macro _("..."), for text not to be translated use _T("...").
Sample code
#include <wx/intl.h> // internationalization
class App: public wxApp {
...
private:
wxLocale m_locale;
...
}
bool App::OnInit () {
...
wxString appPath = wxFileName(argv[0]).GetPath (wxPATH_GET_VOLUME);
if (appPath.IsEmpty()) appPath = wxGetCwd();
wxString appName = wxFileName(argv[0]).GetName();
#ifdef __WXMAC__
appPath += appName + _T(".app/Contents/Resources"));
#endif
m_locale.Init();
m_locale.AddCatalog (appPath + wxFileName::GetPathSeparator() + appName);
...
}
String samples
// no translation, using _T("...")
const wxString APP_MAINT = _T("Otto Wyss");
const wxString APP_VERSION = _T("1.0.3");
const wxString APP_LICENCE = _T("wxWindows");
const wxString APP_COPYRIGTH = _T("(C) 2004 Otto Wyss");
// will be translated, using _("...")
aboutinfo->Add (new wxStaticText(this, -1, _("Written by: ")), 0, wxALIGN_LEFT);
aboutinfo->Add (new wxStaticText(this, -1, APP_MAINT), 1, wxEXPAND | wxALIGN_LEFT);
aboutinfo->Add (new wxStaticText(this, -1, _("Version: ")), 0, wxALIGN_LEFT);
aboutinfo->Add (new wxStaticText(this, -1, APP_VERSION), 1, wxEXPAND | wxALIGN_LEFT);
aboutinfo->Add (new wxStaticText(this, -1, _("Licence type: ")), 0, wxALIGN_LEFT);
aboutinfo->Add (new wxStaticText(this, -1, APP_LICENCE), 1, wxEXPAND | wxALIGN_LEFT);
aboutinfo->Add (new wxStaticText(this, -1, _("Copyright: ")), 0, wxALIGN_LEFT);
aboutinfo->Add (new wxStaticText(this, -1, APP_COPYRIGTH), 1, wxEXPAND | wxALIGN_LEFT);
8.2 Translations