Display wxYES_NO in English regardless of OS language

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Scharl55
In need of some credit
In need of some credit
Posts: 8
Joined: Mon Jun 07, 2010 10:32 pm

Display wxYES_NO in English regardless of OS language

Post by Scharl55 » Thu Dec 16, 2010 9:45 am

Is there a way to make wxYES_NO always actually display "Yes" and "No" instead of displaying the translations of those in the language of the OS?

For instance:

Code: Select all

wxMessageBox("Do you like cats?", "Ultimate question", wxYES_NO);
This displays "Ja" and "Nein" for me but I want it to be "Yes" and "No".

briceandre
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 670
Joined: Tue Aug 31, 2010 6:22 am
Location: Belgium

Post by briceandre » Thu Dec 16, 2010 9:47 am

The display language shall depend on your OS language. So, you should do nothing for that to work, just running your application on an OS configured with proper language.

jfouche
Super wx Problem Solver
Super wx Problem Solver
Posts: 442
Joined: Tue May 06, 2008 4:52 pm
Location: France

Post by jfouche » Thu Dec 16, 2010 10:27 am

You'll have to create your own message box function.
Or you can force the local to english (have a look to wxLocale) :

Code: Select all

class MyApp : public wxApp
{
   wxLocale m_locale;

   ...
};

bool MyApp::OnInit()
{
   m_locale.Init(wxLANGUAGE_ENGLISH_US, wxLOCALE_CONV_ENCODING);
#ifdef __LINUX__
   {
      wxLogNull noLog;
      m_locale.AddCatalog(wxT("fileutils"));
   }
#endif
   ...
}
Jérémie

PB
Part Of The Furniture
Part Of The Furniture
Posts: 2242
Joined: Sun Jan 03, 2010 5:45 pm

Post by PB » Thu Dec 16, 2010 11:36 am

Or, if you're using recent (2.9+) wxWidgets there's a wxMessageDialog.

To my surprise, changing locale works but users don't usually appreciate one application having settings different from those system-wide - e.g. decimal separator. It's sometimes very annoying. On MS Windows, the default behaviour for nonlocalized applications seem to be just to use system locale language for UI labels - message boxes, file open/save dialog etc.

Scharl55
In need of some credit
In need of some credit
Posts: 8
Joined: Mon Jun 07, 2010 10:32 pm

Post by Scharl55 » Thu Dec 16, 2010 4:25 pm

PB wrote:On MS Windows, the default behaviour for nonlocalized applications seem to be just to use system locale language for UI labels - message boxes, file open/save dialog etc.
Personally I've always found this behaviour very annoying when applications ask me questions in English and prompt me to answer in German.
jfouche wrote: Or you can force the local to english (have a look to wxLocale) :

Code
This seems to be a good solution for my problem, but I'm not getting it to work.

Code: Select all

#include <wx/wx.h>

class MyApp:public wxApp
{
    wxLocale m_locale;
    public:
	bool OnInit();
};

IMPLEMENT_APP(MyApp)

bool MyApp::OnInit()
{
    m_locale.Init(wxLANGUAGE_ENGLISH_US, wxLOCALE_CONV_ENCODING);
    wxMessageBox("Success", "?", wxYES_NO); // Still displays "Ja" and "Nein"
}
Am I forgetting something here?

jfouche
Super wx Problem Solver
Super wx Problem Solver
Posts: 442
Joined: Tue May 06, 2008 4:52 pm
Location: France

Post by jfouche » Sun Dec 19, 2010 10:54 am

Hi,

This is probably due to the fact you don't have this locale installed on Windows. As wxWidgets is based on the Win32 API, it will show you the message box according to the locale which has been set. By default, this is the OS locale, but it can be overridden by the SetThreadLocale function (this is what is done by the wxLocale::Init() method). If this locale isn't available on Windows, it doesn't know which label he have to show (Windows doesn't have all translation by default).

I think the better solution for you is to use internationalization for you software :
1 : Write all user labels in English with the _() macro, in order to make it translatable by gettext.
2 : Create a catalog of your software, using Poedit (for example)
3 : add those foreign catalog to your software using wxLocale::AddCatalog().

This way, your software will be available for multiple language according to the user.

Have a look to the internat sample provided with wxWidgets.
Jérémie

Post Reply