xgettext
Extract translatable strings from source code
TLDR
Scan file and output strings to messages.po
Use a different output filename
Append new strings to an existing file
Don't add a header containing metadata to the output file
Display help
SYNOPSIS
xgettext [options] inputfile...
PARAMETERS
--default-domain=NAME
Use NAME.po as name for output (instead of messages.po).
-o, --output=FILE
Write output to specified file.
-d, --domain=NAME
Use NAME.po as name for output file
-p, --directory=DIR
Output files will be placed in directory DIR.
-j, --join-existing
Join messages with existing file.
-x, --exclude-file=FILE
Specify a file containing a list of source files that should not be scanned.
-k, --keyword=WORD
Look for WORD as an additional keyword.
-n, --add-location
Generate ‘#: filename:line’ lines.
--no-location
Do not generate ‘#: filename:line’ lines.
-c, --comment-tag=TAG
Place comments found before keywords in the output file, using TAG as marker.
-C
Use compact output style.
--debug
Enable verbose debugging output.
--files-from=FILE
Get list of input files from FILE.
--from-code=NAME
Encoding of the input files.
-h, --help
Display help message.
-V, --version
Display version information.
DESCRIPTION
xgettext is a program used to extract translatable strings from source code. It parses source files, identifies text strings marked for translation (using special keywords or functions like gettext()), and creates a Portable Object (.po) file.
This .po file serves as a template for translators to provide translations in different languages. The translated versions are then compiled into Message Object (.mo) files, which are used by the application at runtime to display the localized text. xgettext supports various programming languages, making it a crucial tool in the internationalization and localization (i18n/l10n) process. The process involves writing programs with messages that uses gettext functions. Later translators uses xgettext to create catalogs from those sources and provide localized versions for different locales.
CAVEATS
xgettext relies on properly formatted source code to accurately extract strings. Complex or dynamically generated strings may not be correctly identified. Requires GNU gettext tools to be installed.
SUPPORTED LANGUAGES
xgettext supports various programming languages including C, C++, Python, Java, PHP, and more. The exact list and level of support may vary depending on the version and configuration.
WORKFLOW
The typical workflow involves using xgettext to extract translatable strings, providing the resulting .po file to translators, and then using msgfmt to compile the translated .po files into .mo files for use by the application.
HISTORY
xgettext is part of the GNU gettext utilities, which were developed to provide a standardized and open-source solution for internationalization. It has evolved significantly over the years to support a wider range of programming languages and features, becoming a cornerstone in software localization.