This tutorial part is about how to localize core Python plugins so contributors can translate the user interface.
Enable gettext for Python PluginsFor 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.