Gettext MO (Machine Object) file

From Just Solve the File Format Problem
Jump to: navigation, search
File Format
Name Gettext MO (Machine Object) file
Ontology
Extension(s) .mo

From the manpage the gettext program translates a natural language message into the user's language, by looking up the translation in a message catalog.

A Gettext MO file is one of two Gettext file types conveying translations in source code. A Gettext MO file is the second of two files. A first file, a Gettext PO (Portable Object) file, contains strings extracted from the source code for a software application. MO files are generated from PO files. An MO file is a compiled/binary representation of the same data for use by the calling application.

Contents

Compiling MO files from PO files

Given a PO file containing translations, it can be converted to an MO file as follows once gettext is installed locally, e.g. yum install gettext.

The command might look as follows:

  • msgfmt messages.po -o messages.mo

File structure

An excerpt from the documentation describes the structure of MO files as follows:

        byte
             +------------------------------------------+
          0  | magic number = 0x950412de                |
             |                                          |
          4  | file format revision = 0                 |
             |                                          |
          8  | number of strings                        |  == N
             |                                          |
         12  | offset of table with original strings    |  == O
             |                                          |
         16  | offset of table with translation strings |  == T
             |                                          |
         20  | size of hashing table                    |  == S
             |                                          |
         24  | offset of hashing table                  |  == H
             |                                          |
             .                                          .
             .    (possibly more entries later)         .
             .                                          .
             |                                          |
          O  | length & offset 0th string  ----------------.
      O + 8  | length & offset 1st string  ------------------.
              ...                                    ...   | |
O + ((N-1)*8)| length & offset (N-1)th string           |  | |
             |                                          |  | |
          T  | length & offset 0th translation  ---------------.
      T + 8  | length & offset 1st translation  -----------------.
              ...                                    ...   | | | |
T + ((N-1)*8)| length & offset (N-1)th translation      |  | | | |
             |                                          |  | | | |
          H  | start hash table                         |  | | | |
              ...                                    ...   | | | |
  H + S * 4  | end hash table                           |  | | | |
             |                                          |  | | | |
             | NUL terminated 0th string  <----------------' | | |
             |                                          |    | | |
             | NUL terminated 1st string  <------------------' | |
             |                                          |      | |
              ...                                    ...       | |
             |                                          |      | |
             | NUL terminated 0th translation  <---------------' |
             |                                          |        |
             | NUL terminated 1st translation  <-----------------'
             |                                          |
              ...                                    ...
             |                                          |
             +------------------------------------------+

MO files have the magic number: 0x950412de

Example MO files

References

Additional links

Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox