We are currently trying to convert our application using wxPython’s support for locale. However, we have a situation where we have text that is provided as a default argument to a function that we want to translate, but the translation doesn’t happen.
For example,
def AddPage(self, title=_("Empty Page")):
...
If we have a translation for “Empty Page”, the program still uses the raw English version. I’m assuming this is simply due to the way that these arguments are determined during runtime.
For a complete working example of the problem, I have a zip file with the code here: https://drive.google.com/file/d/1X3UZ4ThGhmBcU9cFk0letTEkmWLL_Tu5/view?usp=sharing
In that example, we have “Sample Title Text English” translated to German (fake translation lol, its translated to “Sample Title Text German”), and the app defaults to German locale. PrintTranslation()
is set up with a default of _("Sample Title Text English")
and then should print that text whenever it’s called. However, when that function is called without any parameters, the English version prints out instead of the German version.
The only workaround that I know of would be change the function to something like this:
def PrintTranslation(self, text=None):
text = text or _("Sample Title Text English")
print(text)
This works, but I’m wondering if there’s a better, or more conventional, way of handling this?