Producing a Binary mo File from a po File

Once the translation text has been added to the .po file, the next step is to create the .mo file. This binary file is used by the programs to make translations. The binary file is created using the .po file as input to the msgfmt utility, as follows:

| $ msgfmt starter.po

This command produces a binary file named starter. Recall from the beginning of this chapter that the program starter.c begins with the following three function calls:

setlocale(LC_ALL,""); bindtextdomain(PACKAGE,LOCALEDIR); textdomain(PACKAGE);

The macro PACKAGE is defined as "starter" and LOCALEDIR is defined as "/usr/share/locale". For the program to find the translation tables for, say, Canadian English, it is only necessary to copy the binary file to /usr/share/locale/en_CA/starter. Whenever the current local is set to en_CA, the program will look for, and find, the appropriate translation tables. To create translations for other languages, it is only necessary to edit a copy of starter.po to insert the appropriate translation strings, create another binary file, and copy it to the appropriate subdirectory.

The utility msgfmt has a few command-line options, which are listed in Table 11-4.



-a number

Aligns strings to the specified number of bytes. The default is 1.


Same as -a.


Performs language-dependent checks on the strings. This includes checking for the validity of % formatting sequences in C strings and the correctness of the information being inserted in the header. It also checks that there are no conflicts in the domain name and --output-file option.


Same as -c.

Table 11-4. Command-Line Options for msgfmt



-D directory

Adds the named directory to the list of those to be searched for input files.


Same as -D.


Uses fuzzy entries on input.


Displays this list of options and exits.


Same as -h.


The binary output file will not include the hash table.

-o file

Specifies the name of the output file as file. The default is to use the base name of the input file without an extension.

--output-file file

Same as -o.


Displays statistical information on the translation tables.


Enables the strict Uniforum mode.


Same as - f.


Lists any anomalies found in the input.


Displays version information and quits.


Same as -v.


Same as -V.

Table 11-4. Command-Line Options for msgfmt (continued)

This page intentionally left blank.

Peripherals and Internals

This page intentionally left blank.


Was this article helpful?

0 0

Post a comment