gettext brings the established GNU catalog workflow to Python. Code uses a message key and a compiled catalog supplies the translation for the selected locale.
Practical example
import gettext
translator = gettext.translation(
"messages",
localedir="locales",
languages=["pt_BR"],
fallback=True,
)
_ = translator.gettext
print(_("Welcome"))
From source to catalog
Mark messages with a short function, extract them into PO files, review translations, and compile MO files. Automate extraction so new messages are visible to the localization workflow.
Plural is not concatenation
Use ngettext() with singular and plural forms. Each language defines its own rules, so assembling a sentence with English-specific conditions creates fragile translations.
Context and fallback
Avoid an isolated word when it can have several meanings. Add catalog context and choose deliberately whether fallback=True is acceptable, because it can hide a missing translation.
Keep learning
Strengthen the foundation with Python guide for beginners. The official Python documentation, accessed July 22, 2026, documents the API, limitations, and version differences.