Unknown/unavailable wx.Locale gets a popup warning

If I try to use wx.Locale with a language that is not available on the machine I’m on, then on both Linux and Mac I get a popup window:

image

Can I stop that popup window from popping up? It doesn’t seem to be under my control at all.

The reason I’d like this is that I’m experimenting with i18n for an app, and I’ve heard of a useful trick where you make up a “fake language” to confirm that you’ve done all the translations: that is, I make up a language with code xx-xx or similar, and translate “Hello, world!” into “ℍ𝕖𝕝𝕝𝕠, 𝕨𝕠𝕣𝕝𝕕”, so I can see that it’s all working. Obviously the wx widgets themselves will not be available in this language, and I’m fine with that, but I can’t set wx.Locale to a language that’s not installed on this machine without getting the popup above. What’s the best way to go about this sort of thing?

You can use this:

import wx

fake_language_code = 'xx-XX'

if wx.Locale.IsAvailable(fake_language_code):
    locale = wx.Locale(wx.LANGUAGE_DEFAULT)
    locale.Init(wx.LANGUAGE_DEFAULT)
else:
    print(f"{fake_language_code} is not available. Skipping wx.Locale initialization.")

This code snippet checks if the ‘xx-XX’ language is available before initializing wx.Locale to prevent the popup window issue. Adjust the fake_language_code variable to your specific language code as needed.

1 Like