LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

pygettext

Extract translatable strings from Python code

TLDR

Extract translatable strings
$ pygettext [script.py]
copy
Specify output file
$ pygettext -o [messages.pot] [script.py]
copy
Extract from directory
$ pygettext -d [domain] [src/]
copy
Include docstrings
$ pygettext -D [script.py]
copy

SYNOPSIS

pygettext [options] files...

DESCRIPTION

pygettext extracts translatable strings from Python source code. It searches for strings marked with _(), gettext(), and similar functions, creating a POT template file.Part of Python standard library.

PARAMETERS

-o, --output file

Output file name.
-d, --domain name
Text domain name.
-p, --output-dir dir
Output directory.
-D, --docstrings
Extract docstrings.
-k keyword
Additional keyword to look for.
-n, --add-location
Include file:line comments.

EXAMPLES

$ # Basic extraction
pygettext -o messages.pot *.py

# From directory
pygettext -d myapp -p locale src/*.py

# Include docstrings
pygettext -D -o docs.pot module.py

# Custom keywords
pygettext -k N_ -k ngettext:1,2 app.py
copy

MARKING STRINGS

$ from gettext import gettext as _

message = _("This will be translated")
print(_("Hello, world!"))
copy

OUTPUT FORMAT (POT)

$ #: script.py:10
msgid "Hello, world!"
msgstr ""
copy

CAVEATS

Part of Python. For more features, use xgettext or Babel. Output is template, translators create .po files.

HISTORY

pygettext is part of Python tools for internationalization, implementing gettext extraction for Python.

SEE ALSO

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

Braincup
Open source brain training for math, memory and focus
Braincup mini-games
41 mini-games · Apache-2.0
No ads · No tracking
Play in browser
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid
276 stars
From the maker of Linux Command Library
Copied to clipboard
Braincup
Open source brain training for math, memory and focus. 41 mini-games, from mental arithmetic to Sudoku, N-Back and Solo Chess.
Apache-2.0 licensed · No ads · No tracking · No account
From the maker of Linux Command Library
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid