Working with gettext .po translation files

Gettext is the oldest translation format still in wide use. Django, WordPress, Python and many C and PHP projects read .po files, compiled to .mo for speed.

How a .po file is laid out

Each entry pairs a msgid with a msgstr. The header entry has an empty msgid and carries metadata such as the language and the plural rule. Comments above an entry hold translator notes and source references.

Many projects use the source text as the msgid. LocalizeMe is key-based, so its export writes the key as the msgid and the translation as the msgstr.

locale/de/LC_MESSAGES/django.po
msgid ""
msgstr ""
"Language: de\n"

msgid "checkout.pay_button"
msgstr "Jetzt bezahlen"

Plural forms

Gettext handles plurals with msgid_plural and numbered msgstr[n] entries, chosen by the Plural-Forms rule in the header. LocalizeMe reads these on import, mapping each msgstr[n] to its CLDR form using the language's rules, even when the header leaves the rule out.

The export writes each plural form as its own key today rather than as msgid_plural entries.

Compiling and pulling

Pull the .po files, then compile them as usual.

terminal
localizeme init --project 42 --format po --path 'locale/{locale}/LC_MESSAGES/django.po'
localizeme pull
python manage.py compilemessages

Questions

Can I import .po files with plurals?

Yes. msgid_plural entries import as one key per CLDR plural form, using the header's Plural-Forms rule or the language's own rules when it is missing.

Do I need .pot templates?

No. The keys live in LocalizeMe, so each language exports as a complete .po file with no separate template step.

Other guides

Unlimited strings, one flat price

LocalizeMe never counts keys, strings or languages. Try Pro free for 14 days, no card needed.