msginit
Create new message catalog (.po) files
TLDR
Generate Portable Object files in system locale from messages.pot
Define locale to generate from a specific template
Display help
SYNOPSIS
msginit [OPTION]... INPUT.pot
msginit [OPTION]... INPUT.po
PARAMETERS
-l, --locale=LOCALE
Specify the target locale (e.g., fr, de_DE) for the new PO file.
-i, --input=FILE
Read input from FILE instead of the first non-option argument.
-o, --output=FILE
Write output to FILE instead of the default LOCALE.po.
-e, --encoding=ENCODING
Specify the output character encoding.
-p, --previous
Use previous msgid for fuzzy matching (relevant when initializing from an existing .po).
-w, --width=NUMBER
Wrap output messages at NUMBER columns.
--no-translator
Do not include Last-Translator and Language-Team fields in the header.
--translator='NAME
Set the translator's name and email in the header.
-D, --directory=DIRECTORY
Add DIRECTORY to the list for searching input files.
--color[=WHEN]
Control colored output. WHEN can be always, never, or auto.
--no-color
Equivalent to --color=never.
--style=STYLE
Use a specific style for colored output.
-v, --verbose
Print verbose messages during execution.
-s, --statistics
Print statistics about the output PO file.
--strict
Enable strict checking of PO file syntax.
--warnings=CATEGORY
Enable warnings for a specific CATEGORY (e.g., po-file).
--error-limit=NUMBER
Stop after NUMBER errors are encountered.
--random-seed=NUMBER
Set random seed for reproducible fuzzy hashes.
--id-hash=ALGORITHM
Use specified algorithm (e.g., sha1) for message IDs.
--force-po
Always overwrite existing PO files without prompting.
--sort-output
Sort the output entries in the PO file.
--sort-by-file
Sort entries by file location.
--sort-by-msgid
Sort entries by message ID (default if sorting).
--sort-by-location
Sort entries by location within the source files.
--sort-by-linenum
Sort entries by line number within the source files.
--reverse
Reverse the order of the sorted output.
-c, --comment-out-fuzzy
Comment out fuzzy entries in the output.
-U, --no-wrap
Do not wrap output messages.
-W, --wrap
Wrap output messages (default behavior).
--add-location
Add location information to entries (default).
--no-location
Do not add location information to entries.
-h, --help
Display a help message and exit.
-V, --version
Display version information and exit.
DESCRIPTION
msginit is a utility from the GNU gettext package, used to initialize a new .po (Portable Object) file for a specific language translation. It typically takes an existing .pot (Portable Object Template) file, which contains all translatable strings extracted from source code, and creates a .po file filled with the original strings, ready for translators to add their target language equivalents.
The generated .po file includes a standard header with metadata like project name, version, translator's name, email, and the target language's character set. If an existing .po file is provided as input, msginit can initialize a new .po for a different locale based on the structure and comments of the existing one. This command is crucial for starting a translation project, ensuring the correct structure and initial content for localization efforts.
CAVEATS
When creating a new PO file, msginit does not update the POT-Creation-Date in the generated PO header. This date will reflect the creation date of the original .pot file.
Be mindful of the --force-po option, as it will overwrite an existing PO file without prompt, potentially leading to data loss if not used carefully.
TYPICAL USAGE
To create a new French translation file (fr.po) from a template (messages.pot):
msginit --locale=fr --input=messages.pot --output=fr.po
Alternatively, if messages.pot is the first argument:
msginit -l fr messages.pot
This creates fr.po in the current directory, pre-filled with original strings and ready for French translations.
GETTEXT WORKFLOW CONTEXT
msginit fits into the gettext workflow after source code strings have been extracted into a .pot file (using xgettext) and before translations are added by human translators. After translation, the .po files are then compiled into binary .mo files (using msgfmt) which are used by applications at runtime for displaying localized messages.
HISTORY
msginit is an integral part of the GNU gettext toolset, which was developed in the early 1990s to standardize and streamline the process of internationalizing software. Its inclusion greatly simplified the initial setup of translation projects by automating the creation of PO files from templates, making it a foundational component for enabling multilingual support in countless open-source and proprietary applications.