LANGUAGE_DEFAULT unrecognized on macOS

Hi.
As said in the title, it seems that wx.LANGUAGE_DEFAULT doesn’t really do its job on macOS.

Here is the code I’m using to initialize the wx.Locale var :

class MyApp(wx.App):
    def OnInit(self):
        ..........
        self.InitLanguage()
        ..........

    def InitLanguage(self):
        wx.Locale.AddCatalogLookupPathPrefix("./langs")
        self._locale = wx.Locale()
        if self._locale.Init(wx.LANGUAGE_DEFAULT):
            print("Language initialized to " + self._locale.GetCanonicalName())
        else:
            print("Unable to initialize language to " + self._locale.GetCanonicalName())

        self._locale.AddCatalog("mypofilename")
..........

The ‘Init’ call fails, so I obtain the second print line, but without any information of the language’s canonical name.
The ‘AddCatalog’ line works fine (my specific strings are correctly translated) but the wxWidgets default ones aren’t (for example, the menus labels, …)

If I replace ‘wx.LANGUAGE_DEFAULT’ by ‘wx.LANGUAGE_FRENCH’, all works fine.
But the goal is of course to use the system language.

This code works fine on Windows and on Linux, but not on macOS.

Did I missed something ?

Regards
Xav’

Hi.

Here are some news about this problem.
I’ve tested wx.Locale.GetSystemLanguage() but it returns wx.LANGUAGE_UNKNOWN (so we can think the problem comes from here).

I’ve also tested a similar code with C++ and it returns the correct value on my mac (witch is fr_FR).

Can this be a wxPython bug ?

Regards
Xav’

Hi.

Can one please confirm that this problem doesn’t occurs only on my Mac ?

And is there another solution to detect the default language of the system ?

@Robin : Do I have to create a bug report for this ?

Regards
Xav’

Sorry, I’m not sure I know enough about locale switching to be able to feel confident in giving an answer. So you may want to check at trac.wxwidgets.org or on the wx-users mail list to get authoritative answers.

Some other things to check in the meantime:

  • Do you have any LANG or LC_* environment variables set?
  • Does it make any difference if you override wx.App.InitLocale to do nothing?

Hi.

  • I don’t have any LC_* environment variable set (got the list of all env vars with printenv)
  • LANG env var is set to fr_FR.UTF-8
  • Overriding the wx.App.InitLocale to do nothing doesn’t change anything

I also try some code you talk about in this post.

Running in a simple Python file (or in an IDLE window) the following code:

import locale
loc, enc = locale.getlocale()
print("loc=" + loc + " enc=" + enc)

gives : loc=fr_Fr enc=UTF-8

Calling the same code within the InitLocale method gives an error because loc is None (enc is correctly set to UTF-8)

As I’ve told in my previous post, the following code in C++ works fine:

wxLanguage lng = (wxLanguage)wxLocale::GetSystemLanguage();
wxString sLang = wxLocale::GetLanguageCanonicalName(lng);

The sLang variable is correctly set to fr_FR.

Regards
Xav’