Reputation: 972
I try to create a simple multilingual program using wxLocale, but I can't even get it fail --- looks like any attempts to load language always returns OK, but change nothing.
#include <wx/intl.h>
#include <wx/stdpaths.h>
#include <wx/app.h>
#include <wx/txtstrm.h>
#include <wx/wfstream.h>
wxFFileOutputStream wxstdout (stdout); wxTextOutputStream cout(wxstdout);
wxFFileOutputStream wxstderr (stderr); wxTextOutputStream cerr(wxstderr);
class app: public wxApp
{
public:
virtual bool OnInit();
};
bool app::OnInit()
{
long language = wxLANGUAGE_GERMAN;
wxLocale* locale = new wxLocale();
if (locale->Init(language, wxLOCALE_CONV_ENCODING))
cerr << L"Language loaded OK\n";
else
cerr << L"Language loading failed\n";
cout << _("Hi!") << endl;
exit(0);
return true;
}
IMPLEMENT_APP_CONSOLE(app);
No matter, what language I try to specify, it always print
Language loaded OK
Hi!
I suppose, since there are no translations (.po and .mo files), it should fail to Init
language? However, when I try to actually add some translations it change nothing, program always print Hi!
. Why it all happens?
Upvotes: 0
Views: 1726
Reputation: 20457
You need a call to AddCatalog() after Init.
http://docs.wxwidgets.org/trunk/classwx_translations.html#a3074f9d91c92bd0ade9e6aea4affc652
The domain string is simply the application name.
Take a look at line 247 of the internat sample code
http://svn.wxwidgets.org/viewvc/wx/wxWidgets/trunk/samples/internat/internat.cpp?view=markup
The call to init() simply sets the locale. If the system knows about the locale, it will return success. It does not load your catalog. The return from AddCatalog should tell you if the catalog was found.
If the catalog is not found, you need to install the .mo files with your application in the appropriate location for the target system which is the one returned by wxStandardPaths::GetLocalizedResourcesDir( wxStandardPaths::ResourceCat_Messages ).
Please read the i18b overview at http://docs.wxwidgets.org/trunk/overview_i18n.html
Upvotes: 2
Reputation: 22659
Because that's how localization generally works. You have marked translatable strings and if the translation is not found the original is shown. So, in your case, no German translation files are available, but that doesn't mean that the program can't continue working.
Upvotes: 2