xgettext
Extract translatable strings from source code
TLDR
Extract strings from C
SYNOPSIS
xgettext [-L language] [-k keyword] [-o output] [options] files
DESCRIPTION
xgettext extracts translatable strings from source code files and produces Portable Object Template (.pot) files used in the GNU gettext internationalization workflow. It scans source files for function calls that mark strings for translation, such as _(), gettext(), and N_(), and collects them into a template that translators can use as a starting point.
The tool supports a wide range of programming languages including C, C++, Python, Shell, PHP, Java, Perl, and many others. It can auto-detect the source language from file extensions or accept an explicit language specification via the -L option. Custom extraction keywords can be defined with -k to match project-specific translation functions.
The output .pot file preserves source file locations, translator comments (extracted with --add-comments), and message context. This template serves as the basis for creating language-specific .po files with msginit and keeping them updated with msgmerge as the source code evolves.
PARAMETERS
-o, --output FILE
Output file.-L, --language LANG
Source language.-k KEYWORD
Extraction keyword.-j, --join-existing
Append to existing.-c, --add-comments TAG
Extract comments.--package-name NAME
Package name.--from-code ENC
Source encoding.
CAVEATS
Part of gettext. Keywords must match code. Complex strings need care.
HISTORY
xgettext is part of GNU gettext, the standard internationalization system. It enables software translation workflow.
