I’ve been trying for the last week to make my application international, what I mean by international is simply translated to other languages depending on the system’s locale.
I was able to use gettext to translate certain parts of the application such as the name and About dialog (although I think this is automatically done by the build system):
But other parts like buttons and headerbar texts weren’t translated, even though these are translated in the pt_BR.po file. I also added a print(_(“Download”), where _ = gettext.gettext, but “Download” is also not translated.
Looking around the web I find many solutions on how to “solve” this issue, some are considered hacky, other are more organized (such as Apostrophe’s), but I’d like to know the GNOMEst way of doing translations in python with gettext and GTK.
I looked at your code, and it seems that you’re not calling gettext.textdomain() anywhere. Possibly you may also need to call gettext.bindtextdomain() if your .mo files are not installed into the system-wide directories (/usr/share/locale/xx_XX/LC_MESSAGES/yourgettextdomain.mo).
I’ve also discovered that you may need to call locale.textdomain()/locale.bindtextdomain() if you want GTK itself to translate its own strings (like stock button titles and such).
If you want a working code example, gtimelog is my Python/GTK application that uses gettext for internationalization.
Actually now I see that you are calling gettext.install() from the meson-generated fontdownloader script, so things should work.
OTOH gettext.install() makes _ available in the Python builtin namespace without any need for explicit imports, so perhaps your explicit import statement overrides it with an unbound version, which breaks everything?
Try removing the import statement and seeing if that helps?