I've created an application that I'd like to submit through the Ubuntu app developer process. One of the requirements for the process is that when installed, all files go into the /opt/extras.ubuntu.com/<appname>
directory.
Through changes in packaging and with help from others I've achieved that, but now I'm facing a new problem: when running from /opt
the translations from my app are not being loaded.
What happens is the following: unless specified otherwise, the binary files (MO files) containing translations for an application are loaded from /usr/share/locale
(or in the case of Ubuntu, from /usr/share/locale-langpack
), but in my app, due to the /opt
requirement, they are installed in /opt/extras.ubuntu.com/qreator/locale
.
That's in theory fine, as gettext allows specifying an alternative location to load translations, so I add the bindtextdomain
call to achieve that:
import gettext
from gettext import gettext as _
gettext.bindtextdomain('qreator', '/opt/extras.ubuntu.com/qreator/share/locale/')
gettext.textdomain('qreator')
That works well up to a point: all messages that are output on the command line then appear translated as expected. But it does not solve the main problem: to load the translations from the UI Glade requires specifying the translation domain once more (the equivalent to the gettext.textdomain('qreator')
call above), but it does not let specifying where to load translations from (i.e. the Glade equivalent to bindtextdomain
, which sadly does not exist). Here's an extract of the code that I'm using:
builder = Gtk.Builder()
builder.set_translation_domain('qreator')
# There isn't a way to tell glade to load translations from
# somewhere else than /usr/share/locale here
builder.add_from_file(ui_filename)
This essentially means that translations from the UI cannot be loaded if your app is installed in /opt
.
I'm pretty much stuck at this point. Any ideas on how to make Glade load translations from /opt/extras.ubuntu.com/qreator/share/locale/
instead of /usr/share/locale
?
I've found a solution: use the locale Python module instead of gettext
Thanks to Juha Sahakangas on the #gtk+ IRC channel for providing the explanation: