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.

Option

Description

-a number

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

--alignment=number

Same as -a.

-c

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.

--check

Same as -c.

Table 11-4. Command-Line Options for msgfmt

Option

Description

-D directory

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

--directory=directory

Same as -D.

-f

Uses fuzzy entries on input.

-h

Displays this list of options and exits.

--help

Same as -h.

--no-hash

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.

--statistics

Displays statistical information on the translation tables.

--strict

Enables the strict Uniforum mode.

--use-fuzzy

Same as - f.

-v

Lists any anomalies found in the input.

-V

Displays version information and quits.

--verbose

Same as -v.

--version

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.

Complete

Was this article helpful?

0 0

Post a comment