Gettext PO Files Explained: Plural Forms, Fuzzy Entries and MO Files
Understand gettext PO, POT and MO files, translate plural forms correctly, update a catalog from a new template and compile an MO file in your browser.

Gettext PO Files Explained: Plural Forms, Fuzzy Entries and MO Files
If you have translated a WordPress plugin, a Django site or a Linux program, you have met gettext. It is a decades-old system for translating software, and it is still everywhere because it is simple and robust. Its files look strange at first: a POT file, a PO file per language and a binary MO file that the program actually reads. This guide explains how the three fit together, what plural forms and fuzzy entries are, and how to do the full workflow with the free Gettext PO File Editor without installing anything.
POT, PO and MO
Developers mark translatable strings in their code. A tool then collects them into a POT file, the portable object template. It lists every original string, called msgid, with empty translations and comments that point to the source file and line.
A translator copies the template into a PO file for one language, such as de.po, and fills in each msgstr. PO files are plain text, so they work well in version control and can be read by any editor.
Programs do not parse PO files at run time. They load a compiled MO file, a compact binary table that maps each original string to its translation. Compiling is normally done with the msgfmt command. In the editor, the Compile MO button does the same in your browser.
Contexts and comments
Some entries have a msgctxt line. It separates identical English words with different meanings, such as Order as a button and Order as a noun in a report. Lines that start with a hash and a dot are notes from the developer, and lines with a hash and a colon are references to the code. Read them before translating; they often decide the right word.
Plural forms
English has two forms: one item, two items. Many languages have more. Russian, Ukrainian and Serbian use three, depending on the last digits of the number. Arabic uses six. Japanese and Chinese use one. Gettext handles this with a header line called Plural-Forms. It states how many forms the language has and contains a small formula in C syntax that turns a number into a form index.
For an entry with a plural, the PO file holds one translation per form, msgstr[0], msgstr[1] and so on. The editor reads the formula, evaluates it safely and labels each box with example numbers. For Russian you would see form 0 for 1, 21 and 31, form 1 for 2, 3 and 4, and form 2 for 5 to 20. Type any number into the test field to see which form it selects. If the header is missing or wrong, choose a preset from the gettext manual for your language.
Fuzzy entries
A fuzzy flag marks a translation that needs checking. It appears when a tool guessed the translation from a similar old string, or when a translator was unsure. Fuzzy entries are not used at run time: msgfmt leaves them out of the MO file, and so does the editor. That is a safety feature, because a wrong guess is worse than English text. Review each fuzzy entry, compare it with the previous source string shown above it, edit if needed and untick Fuzzy.
Updating from a new template
When developers change the code, they regenerate the POT. Translators then need to merge it into their PO file. The editor's Update from POT button does what msgmerge does: unchanged strings keep their translations, new strings are added empty, slightly changed strings get the old translation as a fuzzy guess, and removed strings become obsolete entries at the end of the file. The report tells you how many of each, so you know exactly how much work is waiting. You can set the similarity threshold for fuzzy guesses.
Format strings
Many strings contain placeholders such as a percent sign followed by s or d, or a named python placeholder. If a translation drops one, the program may crash or show nonsense. Entries flagged as c-format, python-format or php-format are checked, and problems are listed under Format issues.
Shipping the translation
When the catalog is complete, download the PO for your repository and press Compile MO. For WordPress, name the files with the text domain and locale, such as my-plugin-de_DE.po and .mo, and place them in the languages folder. For Python, put the MO file in the locale folder under LC_MESSAGES. Keep the PO file as your source; the MO file can always be rebuilt from it, while an MO file does not contain your comments or references. Test the result in the running program before release, because only real screens show whether a translation fits.



