This guide explains how to contribute translations to a Bengal site using the standard gettext PO workflow.
PO File Structure
Translations live in:
i18n/
├── en/LC_MESSAGES/messages.po
├── es/LC_MESSAGES/messages.po
└── ar/LC_MESSAGES/messages.po
Each.pofile contains:
- Header: Metadata (charset, plural forms)
- Entries:
msgid(source) andmsgstr(translation)
PO File Format
# English translations for My Site
msgid ""
msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"MIME-Version: 1.0\n"
msgid "Home"
msgstr "Home"
msgid "About"
msgstr "About"
msgid "Read more"
msgstr "Read more"
- msgid: The source string (from templates)
- msgstr: The translation. Empty
msgstr ""means untranslated (fallback to key)
Conventions
- Use UTF-8 for all PO files. Set
Content-Type: text/plain; charset=UTF-8in the header. - Keep msgid unchanged — it's the lookup key. Never translate the msgid.
- Preserve placeholders — if the source has
{name}, keep it in the translation:Hola {name}. - Plural forms — use
msgid_pluralandmsgstr[0],msgstr[1]for languages with plural rules.
Workflow for Contributors
- Get the template: Ask the maintainer for
messages.potor runbengal i18n extractin the repo. - Create your locale:
mkdir -p i18n/XX/LC_MESSAGES(e.g.XX=frfor French). - Copy and translate: Copy
messages.pottoi18n/XX/LC_MESSAGES/messages.poand fill inmsgstrvalues. - Submit: Open a PR with your new or updated
.pofile.
Tools
- Poedit: GUI editor for PO files, handles plural forms
- Lokalize: KDE translation tool
- VS Code: Extensions like "Gettext" for PO editing
Checking Your Work
After adding translations:
bengal i18n compile
bengal build
bengal i18n status
bengal i18n statusshows coverage. Aim for 100% for your locale.
Plural Forms
For strings with counts (e.g. "1 item" vs "5 items"):
msgid "%d item"
msgid_plural "%d items"
msgstr[0] "%d elemento"
msgstr[1] "%d elementos"
The plural rule depends on the language. See Unicode CLDR for rules.