Python-template: gettext usage non obvious
Submitted by sim..@..web.de
Link to original bug (#780461)
Description
Call me stupid, but when using Builder to create a new Gnome application in Python it was totally non obvious how to use gettext to make use of the translation stuff in the project template. For days I was searching the net and trying to get it working properly, until on accident I discovered that the built project sets up gettext just fine.
(It does so here: https://github.com/GNOME/gnome-builder/blob/6cd45c868494701c766eb9779b4651ce8ee721fb/plugins/autotools-templates/autotools_templates/resources/bin/wrapper.py )
So after trying pretty much everything on https://docs.python.org/3/library/gettext.html and looking through all the gettext examples, in the end it turns out all one has to do is to specify the _ function as gettext.gettext, as everything else is already preconfigured.
Since the template provides translation infrastructure I think it would be reasonable to make it work by declaring the _ function as follows in https://github.com/GNOME/gnome-builder/blob/6cd45c868494701c766eb9779b4651ce8ee721fb/plugins/autotools-templates/autotools_templates/resources/src/main.py#L7 :
import gettext import builtins builtins._ = gettext.gettext
This makes it work in all parts of the project. Not all users may want _ in globals, but this is the main.py template they start programming with, so it's easily changeable for everyone.