LinuxCommandLibrary

pygettext3.4

Extract translatable strings from Python source code

SYNOPSIS

pygettext3.4 [options] inputfile1.py inputfile2.py ...

PARAMETERS

-a
    Extract all strings, including those marked with '#: no-translatable'.

-d, --default-domain=NAME
    Use NAME.pot for output file.

-E, --escape
    Replace non-ASCII characters with escape sequences.

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

-i, --input=FILE
    Read input from FILE.

-j
    Join existing file.

-k, --keyword=WORD
    Functions to be recognized as keywords (can be repeated).
Defaults to: _

-K, --no-default-keywords
    Don't use default keywords.

-l, --language=LANG
    Recognize input files as LANG language.

-n, --add-location
    Add file location comments.

-N, --no-location
    Do not add file location comments.

-p, --output-dir=DIR
    Output files will be placed in directory DIR.

-v, --verbose
    Be verbose.

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

-x, --exclude-file=FILE
    Specify a file that contains a list of file names to exclude from being examined.

DESCRIPTION

pygettext3.4 is a command-line tool, part of the Python standard library's gettext module, used to extract translatable strings from Python source code files. It searches through specified Python files for strings that are arguments to _(...) functions (or other functions specified with the -k option) and generates a Portable Object Template (.pot) file. This .pot file serves as a template for translators, providing a list of strings needing translation. This tool simplifies the internationalization process by automating the extraction of translatable text, allowing developers to focus on code while providing translators with a clear, organized list of strings to work on.

It is important to note that pygettext3.4 specifically refers to the Python 3.4 version of this tool. More recent versions are often called simply pygettext or are available within the gettext module itself. Using the correct version corresponding to the Python version of your project is crucial to avoid compatibility issues.

USAGE EXAMPLE

To extract translatable strings from myfile.py and create a messages.pot file, the command would be:
pygettext3.4 myfile.py

This assumes the default domain (messages.pot) and the default keyword (_). To specify a different output file or keyword, use the -d and -k options, respectively.

ENCODING

pygettext typically assumes the input files are encoded in UTF-8. If your files use a different encoding, be aware that this might affect the accuracy of the extracted strings.

HISTORY

pygettext was originally developed as a standalone script for extracting translatable strings from Python code. Over time, it became integrated into the Python standard library within the gettext module. The pygettext3.4 variant specifically refers to the version bundled with Python 3.4. Later versions simplified the naming, making pygettext the standard command (and often a symbolic link). It is fundamental for generating .pot files to start the translation process.

SEE ALSO

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

Copied to clipboard