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 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
    t = gettext.translation("liferea")
except FileNotFoundError:
    _ = t.gettext
And 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.


Also check out the previous plugin tutorial posts