Format:GNU gettext message catalog (MO)
| Magic | DE 12 04 95 (little-endian file, value 0x950412DE) or 95 04 12 DE (big-endian file) |
|---|---|
| Extensions | .mo, .gmo |
| Endianness | either; the magic tells which |
| License | gettext runtime GPL/LGPL |
| Website | https://www.gnu.org/software/gettext/manual/html_node/MO-Files.html |
| On this wiki | Facts · Code · Notes · Topics |
Binary message catalog of GNU gettext (.mo, in locale/<lang>/LC_MESSAGES/<domain>.mo): a 28-byte header with magic 0x950412DE (stored in the writer's byte order, so DE 12 04 95 on big-endian files), a revision, string counts, two tables of (length, offset) pairs for the original and translated strings, and an optional hash table.
Overview
A .mo file is what msgfmt compiles from a .po catalog and what gettext()/dgettext() read at run time. Programs (Linux/Unix software, many cross-platform and Windows ports) ship one per language and domain, usually under share/locale/<lang>/LC_MESSAGES/<domain>.mo or next to the executable. Strings are looked up by their original (usually English) text, so an .mo file lists every user-visible message of a program in clear text: a quick way to learn what a stripped binary says. Compare Format:Qt translation and Format:Resources.arsc (Android strings).
Header
All fields are 32-bit; the writer's byte order is used and the reader detects it from the magic (the runtime checks magic == 0x950412de and 0xde120495 and byte-swaps in the second case).
| Offset | Field |
|---|---|
| 0 | magic 0x950412DE |
| 4 | revision (format revision: major in the high 16 bits, minor in the low; 0 is the usual value, 1 adds system-dependent strings) |
| 8 | nstrings: number of string pairs |
| 12 | orig_tab_offset: offset of the table of original strings |
| 16 | trans_tab_offset: offset of the table of translated strings |
| 20 | hash_tab_size: size of the hash table (0 = none) |
| 24 | hash_tab_offset: offset of the hash table |
Revision 1 files extend the header with n_sysdep_segments, sysdep_segments_offset, n_sysdep_strings, orig_sysdep_tab_offset and trans_sysdep_tab_offset (5 more fields). See Fact:GNU gettext message catalog (MO)/struct/mo_file_header.
Tables
Each of the two tables has nstrings entries of 8 bytes: length (without the terminating NUL) and offset (from the start of the file). Every string is NUL terminated. Original strings are sorted (byte order) so a reader can binary search when there is no hash table. The hash table holds hash_tab_size 32-bit entries (the gettext tooling picks a prime larger than 4/3 of nstrings, unverified here), each 0 or an index+1 into the string tables, using open addressing (Unverified: the entry encoding and probing, not read this session); the hash is the PJW/ELF-style function __hash_string in hash-string.c (read) (shift left 4, add byte, fold the top nibble back in).
Special entries: the empty original string "" is translated by the catalog header (Content-Type: text/plain; charset=UTF-8, Plural-Forms: nplurals=2; plural=(n != 1);, Language, ...), so its translation tells the charset and plural rule. Plural messages store the singular and plural msgid joined by a NUL in the original table and all plural forms joined by NULs in the translation. A message with context (msgctxt) is stored as context, byte 0x04, then msgid.
Identification
A file that starts DE 12 04 95 or 95 04 12 DE is a catalog. Programs call gettext, dgettext, ngettext, bindtextdomain, textdomain; libintl exports may be named libintl_gettext and so on, and intl.dll/libintl-8.dll is the Windows build of the library.
Code & repositories
- https://github.com/autotools-mirror/gettext @
8616f440229337515b38d9b914dcd499369c9cb6· license: GPL-3.0-or-later (declared by the contributor for the files used; GitHub reports GPL-3.0 for the repository)
GNU gettext mirror; gettext-runtime/intl/gmo.h and loadmsgcat.c define and read the .mo format.
Tested on: source read, not run: source read · checked 2026-10-18; last activity 2026-10-18
Pitfalls
- The string offsets are absolute file offsets; do not assume the strings are in table order.
- Translated text may be in a legacy charset: read the
charset=in the header entry. - Unverified: the msgctxt separator 0x04 and plural NUL joining are from the gettext manual, not read in the source this session.
Evidence & references
- https://github.com/autotools-mirror/gettext at commit 8616f440229337515b38d9b914dcd499369c9cb6 (GPL/LGPL):
gettext-runtime/intl/gmo.hlines 25-31 (magic, revisions) and 72-104 (struct mo_file_header), 106-113 (string_desc);gettext-runtime/intl/loadmsgcat.clines 804 and 834 (magic check and byte swap decision);gettext-runtime/intl/hash-string.c(__hash_string). - GNU gettext manual, section "The Format of GNU MO Files".