Next: , Up: Producing Binary MO Files   [Contents][Index]


10.1 Invoking the msgfmt Program

msgfmt [option] filename.po …

The msgfmt programs generates a binary message catalog from a textual translation description.

10.1.1 Input file location

filename.po …
-D directory
--directory=directory

Add directory to the list of directories. Source files are searched relative to this list of directories. The resulting binary file will be written relative to the current directory, though.

If an input file is ‘-’, standard input is read.

10.1.2 Operation mode

-j
--java

Java mode: generate a Java ResourceBundle class.

--java2

Like –java, and assume Java2 (JDK 1.2 or higher).

--csharp

C# mode: generate a .NET .dll file containing a subclass of GettextResourceSet.

--csharp-resources

C# resources mode: generate a .NET .resources file.

--tcl

Tcl mode: generate a tcl/msgcat .msg file.

--qt

Qt mode: generate a Qt .qm file.

--desktop

Desktop Entry mode: generate a .desktop file.

--xml

XML mode: generate an XML file.

10.1.3 Output file location

-o file
--output-file=file

Write output to specified file.

--strict

Direct the program to work strictly following the Uniforum/Sun implementation. Currently this only affects the naming of the output file. If this option is not given the name of the output file is the same as the domain name. If the strict Uniforum mode is enabled the suffix .mo is added to the file name if it is not already present.

We find this behaviour of Sun’s implementation rather silly and so by default this mode is not selected.

If the output file is ‘-’, output is written to standard output.

10.1.4 Output file location in Java mode

-r resource
--resource=resource

Specify the resource name.

-l locale
--locale=locale

Specify the locale name, either a language specification of the form ll or a combined language and country specification of the form ll_CC.

-d directory

Specify the base directory of classes directory hierarchy.

--source

Produce a .java source file, instead of a compiled .class file.

The class name is determined by appending the locale name to the resource name, separated with an underscore. The ‘-d’ option is mandatory. The class is written under the specified directory.

10.1.5 Output file location in C# mode

-r resource
--resource=resource

Specify the resource name.

-l locale
--locale=locale

Specify the locale name, either a language specification of the form ll or a combined language and country specification of the form ll_CC.

-d directory

Specify the base directory for locale dependent .dll files.

The ‘-l’ and ‘-d’ options are mandatory. The .dll file is written in a subdirectory of the specified directory whose name depends on the locale.

10.1.6 Output file location in Tcl mode

-l locale
--locale=locale

Specify the locale name, either a language specification of the form ll or a combined language and country specification of the form ll_CC.

-d directory

Specify the base directory of .msg message catalogs.

The ‘-l’ and ‘-d’ options are mandatory. The .msg file is written in the specified directory.

10.1.7 Desktop Entry mode operations

--template=template

Specify a .desktop file used as a template.

-k[keywordspec]
--keyword[=keywordspec]

Specify keywordspec as an additional keyword to be looked for. Without a keywordspec, the option means to not use default keywords.

-l locale
--locale=locale

Specify the locale name, either a language specification of the form ll or a combined language and country specification of the form ll_CC.

-d directory

Specify the directory where PO files are read. The directory must contain the ‘LINGUAS’ file.

To generate a ‘.desktop’ file for a single locale, you can use it as follows.

msgfmt --desktop --template=template --locale=locale \
  -o file filename.po …

msgfmt provides a special "bulk" operation mode to process multiple .po files at a time.

msgfmt --desktop --template=template -d directory -o file

msgfmt first reads the ‘LINGUAS’ file under directory, and then processes all ‘.po’ files listed there. You can also limit the locales to a subset, through the ‘LINGUAS’ environment variable.

For either operation modes, the ‘-o’ and ‘--template’ options are mandatory.

10.1.8 XML mode operations

--template=template

Specify an XML file used as a template.

-L name
--language=name

Specifies the language of the input files.

-l locale
--locale=locale

Specify the locale name, either a language specification of the form ll or a combined language and country specification of the form ll_CC.

-d directory

Specify the base directory of .po message catalogs.

To generate an XML file for a single locale, you can use it as follows.

msgfmt --xml --template=template --locale=locale \
  -o file filename.po …

msgfmt provides a special "bulk" operation mode to process multiple .po files at a time.

msgfmt --xml --template=template -d directory -o file

msgfmt first reads the ‘LINGUAS’ file under directory, and then processes all ‘.po’ files listed there. You can also limit the locales to a subset, through the ‘LINGUAS’ environment variable.

For either operation modes, the ‘-o’ and ‘--template’ options are mandatory.

10.1.9 Input file syntax

-P
--properties-input

Assume the input files are Java ResourceBundles in Java .properties syntax, not in PO file syntax.

--stringtable-input

Assume the input files are NeXTstep/GNUstep localized resource files in .strings syntax, not in PO file syntax.

10.1.10 Input file interpretation

-c
--check

Perform all the checks implied by --check-format, --check-header, --check-domain.

--check-format

Check language dependent format strings.

If the string represents a format string used in a printf-like function both strings should have the same number of ‘%’ format specifiers, with matching types. If the flag c-format or possible-c-format appears in the special comment #, for this entry a check is performed. For example, the check will diagnose using ‘%.*s’ against ‘%s’, or ‘%d’ against ‘%s’, or ‘%d’ against ‘%x’. It can even handle positional parameters.

Normally the xgettext program automatically decides whether a string is a format string or not. This algorithm is not perfect, though. It might regard a string as a format string though it is not used in a printf-like function and so msgfmt might report errors where there are none.

To solve this problem the programmer can dictate the decision to the xgettext program (see C Format Strings). The translator should not consider removing the flag from the #, line. This "fix" would be reversed again as soon as msgmerge is called the next time.

--check-header

Verify presence and contents of the header entry. See Filling in the Header Entry, for a description of the various fields in the header entry.

--check-domain

Check for conflicts between domain directives and the --output-file option

-C
--check-compatibility

Check that GNU msgfmt behaves like X/Open msgfmt. This will give an error when attempting to use the GNU extensions.

--check-accelerators[=char]

Check presence of keyboard accelerators for menu items. This is based on the convention used in some GUIs that a keyboard accelerator in a menu item string is designated by an immediately preceding ‘&’ character. Sometimes a keyboard accelerator is also called "keyboard mnemonic". This check verifies that if the untranslated string has exactly one ‘&’ character, the translated string has exactly one ‘&’ as well. If this option is given with a char argument, this char should be a non-alphanumeric character and is used as keyboard accelerator mark instead of ‘&’.

-f
--use-fuzzy

Use fuzzy entries in output. Note that using this option is usually wrong, because fuzzy messages are exactly those which have not been validated by a human translator.

10.1.11 Output details

--no-convert

Don’t convert the messages to UTF-8 encoding. By default, messages are converted to UTF-8 encoding before being stored in a MO file; this helps avoiding conversions at run time, since nowadays most locales use the UTF-8 encoding.

--no-redundancy

Don’t pre-expand ISO C 99 <inttypes.h> format string directive macros. By default, messages that are marked as c-format and contain ISO C 99 <inttypes.h> format string directive macros are pre-expanded for selected platforms, and these redundant expansions are stored in the MO file. These redundant expansions make the translations of these messages work with the gettext implementation in the libc of that platform, without requiring GNU gettext’s libintl. The platforms that benefit from this pre-expansion are those with the musl libc.

-a number
--alignment=number

Align strings to number bytes (default: 1).

--endianness=byteorder

Write out 32-bit numbers in the given byte order. The possible values are big and little. The default is little.

MO files of any endianness can be used on any platform. When a MO file has an endianness other than the platform’s one, the 32-bit numbers from the MO file are swapped at runtime. The performance impact is negligible.

This option can be useful to produce MO files that are optimized for one platform.

--no-hash

Don’t include a hash table in the binary file. Lookup will be more expensive at run time (binary search instead of hash table lookup).

10.1.12 Informative output

-h
--help

Display this help and exit.

-V
--version

Output version information and exit.

--statistics

Print statistics about translations. When the option --verbose is used in combination with --statistics, the input file name is printed in front of the statistics line.

-v
--verbose

Increase verbosity level.


Next: Invoking the msgunfmt Program, Up: Producing Binary MO Files   [Contents][Index]