Introduction
GNU gettext is the system that most
free software uses to show its messages in the reader’s language. A program marks the
strings it shows; the translations of those strings live in files of three kinds, which
this family covers: .pot templates, .po catalogues and
.mo compiled catalogues. The first two are text and the third is binary.
They follow one another. xgettext reads the program’s source and writes the
template, with every message and no
translation. A translator starts a PO catalogue
for a language from it and fills in the translations; msgmerge carries the
catalogue over to later templates. msgfmt compiles the catalogue to an
MO file, which the program loads when
it runs. msgunfmt goes back from the MO file to text.
The three have one subject, a table of messages and their translations, with contexts and plural forms, and the header entry that tells the program the language’s plural rule and encoding. The PO and POT files share one syntax, so the explorer reads them with one reader. The MO file is a different thing in layout: sorted tables, a hash table and an encoding of its own for contexts and plurals. They are kept as variations of one family so they can be read side by side.
Variations
| Format | Variation | About | Open |
|---|---|---|---|
.PO | gettext PO message catalogue | Text catalogue of messages and their translations: entries, plurals, contexts and comments. | Open |
.POT | gettext POT template | Translation template: every message of a program, with empty translations. | Open |
.MO | gettext MO binary catalogue | Compiled catalogue: sorted string tables and a hash table, in either byte order. | Open |
gettext PO message catalogue
The text catalogue that a translator edits: entries of an original message and its translation, optionally with a context, plural forms, comments, flags and a header entry, and obsolete entries commented out. It is written in one encoding, named in its header.
It is text, usually starting with comment lines or msgid "". The
keywords msgid and msgstr are what tell it from other text.
A .po file can also be an Apple II disk image in ProDOS order; that is a
different format with a different extension’s meaning, listed under
Also used for below.
gettext POT template
A PO file made by xgettext from a program’s source: the same syntax, with
empty translations and a header entry full of placeholders, such as
charset=CHARSET.
It is told from a catalogue by its extension and its contents: every msgstr is
empty. The extension .pot is also that of PowerPoint templates, a
binary format that starts with the bytes D0 CF 11 E0; a gettext template
is plain text.
gettext MO binary catalogue
The compiled catalogue: the originals and translations in two tables sorted for searching, with a hash table to find an original at once. It has a revision 1 with system-dependent strings, and is written in the byte order of the machine that made it.
It starts with the four bytes DE 12 04 95 (little-endian) or
95 04 12 DE (big-endian), the magic number 0x950412de.
Telling them apart
The explorer looks at the first bytes. The magic number, in either order, is an MO
file. Anything else that is text is read as a catalogue or a template; the two share one
reader, and a file named .pot whose translations are all empty is shown
as a template.
Not described
Each variation’s own page lists what its reference and viewer do not yet cover: PO, POT and MO.
Known, not yet covered
- Reference and viewer: the other outputs of
msgfmt(Java classes, .NET resources, Tcl, Qt, and others), which are other formats. - Viewer: editing; the explorer only reads.
Also used for
- Apple II disk image (ProDOS order) – The sectors of an Apple II floppy or the blocks of a ProDOS volume in ProDOS order.
- PowerPoint 97–2003 presentation – PowerPoint’s binary presentation before PPTX: nested records in a compound file.
Links
Software
- GNU gettext – the tools that make, merge, check and compile the files: xgettext, msginit, msgmerge, msgfmt and msgunfmt (Linux, macOS, Windows)
- Poedit – translation editor for PO files (Windows, macOS, Linux)
- Lokalize – KDE’s translation editor (Linux, Windows)
- Weblate – web-based translation platform that keeps PO files in step with a repository
Developers
- polib – reads and writes PO and MO files (Python)
- Babel – internationalisation library with PO and MO support (Python)
- gettext-parser – parses and compiles PO and MO files (JavaScript)
- Translate Toolkit – converts between PO and many other localisation formats (Python)
Reference
- GNU gettext utilities – the manual, with the chapters on PO files and MO files
- gettext source code – the repository