LinuxCommandLibrary

msgcat

Concatenate and translate message catalog files

TLDR

Combine multiple .po files into one

$ msgcat [file1.po file2.po ...] [[-o|--output-file]] [combined.po]
copy

Combine input files listed in a text file
$ msgcat [[-f|--files-from]] [path/to/file_list.txt] [[-o|--output-file]] [combined.po]
copy

Set the output encoding (e.g. UTF-8)
$ msgcat [[-t|--to-code]] [UTF-8] [input.po] [[-o|--output-file]] [output.po]
copy

Output only unique messages (appearing in one file only)
$ msgcat [[-u|--unique]] [file1.po file2.po ...] [[-o|--output-file]] [unique.po]
copy

Use the first available translation for duplicate entries
$ msgcat --use-first [file1.po file2.po ...] [[-o|--output-file]] [output.po]
copy

Display help
$ msgcat [[-h|--help]]
copy

SYNOPSIS

msgcat [OPTION]... [FILE]...

PARAMETERS

-o FILE, --output-file=FILE
    Write output to specified FILE instead of standard output.

--sort-output
    Sort entries in the output PO file alphabetically by message ID.

--use-first
    When duplicate message IDs are found, use the translation from the first encountered file.

--use-last
    When duplicate message IDs are found, use the translation from the last encountered file.

--force-po
    Force writing output in PO file syntax, even if some translations are missing or malformed.

--width=COLUMNS
    Set the output page width to COLUMNS for formatting.

-h, --help
    Display a help message and exit.

-V, --version
    Display version information and exit.

DESCRIPTION

msgcat is a utility from the GNU gettext toolset, designed to concatenate and merge multiple Portable Object (PO) files into a single consolidated PO file. PO files are plaintext files used for internationalization and localization, containing original strings and their corresponding translations.

msgcat is particularly useful when translations for a project are split across several files or when multiple contributors provide separate translation fragments. It intelligently handles duplicate message IDs, typically preserving the first encountered translation or the most complete one if variations exist. This command simplifies the process of creating a unified translation file, which can then be compiled into a machine-readable MO (Machine Object) file using msgfmt for use by applications. It's an essential tool for maintaining large or distributed translation projects.

CAVEATS

msgcat is primarily for concatenation and simple merging. For more advanced merging operations, such as updating translations against a new template, msgmerge is the more appropriate tool. Handling of conflicting translations for the same message ID (e.g., different translations for the same source string) is controlled by options like --use-first or --use-last; without them, behavior might depend on internal heuristics or the gettext version.

USE CASES

A common use case for msgcat is combining translation fragments from various modules of a large application into a single, cohesive translation file. It can also be used to merge translations from multiple contributors who might have worked on separate parts of the localization effort. The output can then be compiled into a binary .mo file for runtime use by applications.

HISTORY

msgcat is an integral part of the GNU gettext internationalization and localization (i18n/L10n) framework. The gettext project was initiated in the early 1990s to provide a standardized way for programs to support multiple human languages. msgcat, along with other tools like xgettext, msgmerge, and msgfmt, evolved as essential components of this robust system for managing software translations. Its core purpose remains consistent: to help aggregate and manage translation units in .po files.

SEE ALSO

msgmerge(1), xgettext(1), msgfmt(1), gettext(1)

Copied to clipboard