gettext.translation()
gettext.translation() is a Python function in the Gettext Module category. Loads a translation file (.mo) and returns a GNUTranslations object. The syntax is gettext.translation(domain, localedir=None, languages=None, class_=None, fallback=False, codeset=None). Returns: GNUTranslations object. A typical example: import gettext
# Load French translation
trans = gettext.translation("myapp", localedir="locale", languages=["fr"])
trans.install()
print(_("Hello")) # Prints French translation. A close sibling is gettext.gettext(), which returns the translated version of a message (alias _()). A close sibling is gettext.install(), which installs _() in Python's builtins for easy translation calls. More about this category: Internationalization — translation, find, textdomain, bindtextdomain, gettext. Related Gettext Module entries: gettext.gettext(), gettext.install(). This page is part of the free Python Reference documentation covering 978+ functions, methods, and modules with examples and parameter details. You can try gettext.translation() immediately in the Python playground, look up unfamiliar terms in the glossary, or return to the Python Reference homepage.