I'm new to GUI programming with python and I need a simple example about how to change GUI language based on .po files (that I AM able to generate) located inside the project. I'm using GNOME Builder for this task.
What I'd like is to load the gui definition from xml as produced by builder (or Glade) and let the program change texts based on my computer's locale/language.
test
|
|- po
| |- it.po
| |- en.po
| |- ...
|
|- src
| |- test.in
| |- main.py
| |- window.py
| |- window.ui
| |- ...
This the file containing the main UI calss
#window.py
from gi.repository import Gtk
@Gtk.Template(resource_path='/path/to/ui/window.ui')
class TestWindow(Gtk.ApplicationWindow):
__gtype_name__ = 'TestWindow'
label = Gtk.Template.Child()
def __init__(self, **kwargs):
super().__init__(**kwargs)
print(_("hello"))
I discovered that changing the language of strings I put inside the code is as simple as writing
_("some string")
So when loading window.py I get "ciao" in the terminal (italian for hello). But I can't seem to change the language of GUI's widgets, for instance I see "Random Text" and not "Testo a caso" (again, italian translation).
Is there any parameter I can pass to Gtk.Template, or some python magic I can do to modify this behaviour?