Writing liferea plugins tutorial part 5
This tutorial part is about how to localize core Python plugins so
contributors can translate the user interface.
Enable gettext for Python Plugins
For a good plugin example have a look at the Liferea plugins headerbar.py where Robbie Cooper added gettext support. To do so add this code in global scope:# Initialize translations for tooltips # Fallback to English if gettext module can't find the translations # (That's possible if they are installed in a nontraditional dir) import gettext _ = lambda x: x try: t = gettext.translation("liferea") except FileNotFoundError: pass else: _ = t.gettextAnd now everywhere you need it you can use translated literals, e.g.
button.set_tooltip_text(_("Previous Item"))Note the _() style which is the gettext wrapper to replace text with translations.
Related
Also check out the previous plugin tutorial posts- Plugin Tutorial Part 1 (Plugin Boiler Plate)
- Plugin Tutorial Part 2 (Acessing and modify UI elements)
- Plugin Tutorial Part 3 (Adding menu elements)
- Plugin Tutorial Part 4 (Using GTK inspector)
- Plugin Tutorial Part 5 (Enabling translations for plugins)