← 返回命令列表

Linux command

xgettext 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Extract strings from C

xgettext -o [messages.pot] [*.c]

Extract from Python

xgettext -L Python -o [messages.pot] [*.py]

Extract with keyword

xgettext -k_ -o [messages.pot] [*.c]

Join with existing

xgettext -j -o [messages.pot] [*.c]

Add comments

xgettext --add-comments=TRANSLATORS -o [messages.pot] [*.c]

Set package info

xgettext --package-name=[MyApp] --package-version=[1.0] -o [messages.pot] [*.c]

说明

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.

参数

-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.

FAQ

What is the xgettext command used for?

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.

How do I run a basic xgettext example?

Run `xgettext -o [messages.pot] [*.c]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -o, --output _FILE_ do in xgettext?

Output file.