Skip to main content

django-makemessages-rs

PyPI License: MIT

A fast Rust alternative to Django's makemessages command. Produces byte-identical .po file output compared to django-extended-makemessages.

Tested against a ~2000 file Django project with ~3000 translatable strings across 5 locales:

Tool Time
django-extended-makemessages ~21s
django-makemessages-rs ~0.3s

Install

pip install django-makemessages-rs

Platform wheels are available for macOS (arm64, x86_64) and Linux (x86_64, aarch64).

Usage

django-makemessages-rs \
  -l en -l zh_Hant -l zh_Hans -l ko -l ja \
  --ignore .venv --ignore node_modules \
  --no-location --no-flags --sort-output \
  --no-fuzzy-matching --keep-header \
  --locale-dir locale

CI check mode

Use --check to verify translation files are in sync with source code. Exits with code 1 if any .po file would change:

django-makemessages-rs \
  -l en -l zh_Hant \
  --ignore .venv --ignore node_modules \
  --no-location --no-flags --sort-output \
  --no-fuzzy-matching --keep-header \
  --locale-dir locale \
  --check

Options

-l, --locale <LOCALES>       Locales to generate (repeatable)
-x, --exclude <LOCALES>      Locales to exclude (repeatable)
-a, --all                    Update all existing locales
-s, --symlinks               Follow symlinks to directories when scanning
-i, --ignore <PATTERNS>      Patterns to ignore (directories/files)
    --no-default-ignore      Don't ignore CVS, .*, *~, *.pyc
-d, --domain <DOMAIN>        Domain name: django or djangojs [default: django]
-e, --extension <EXTS>       File extensions to examine [default: html txt py, or js for djangojs]
-k, --keyword <SPEC>         Extra xgettext keywordspec, e.g. -k t or -k t:1c,2
                             (repeatable; -k '' drops the defaults)
    --add-comments [TAG]     Emit preceding comments as #. lines
                             [default tag: Translators; bare = all comments]
    --detect-aliases         Treat `import gettext as x` aliases as keywords
    --root <PATH>            Root directory to scan [default: .]
    --locale-dir <PATH>      Locale directory [default: locale]
    --locale-path <PATH>     Extra locale directories, like LOCALE_PATHS (repeatable)
    --per-app-locale         Write into each app's own locale/ dir, like Django
    --no-location            Don't write #: filename:line lines (shorthand for --add-location never)
    --add-location <MODE>    Controls #: location comments: full (default), file, or never
    --no-flags               Don't write #, flags lines
    --sort-output            Generate sorted output
    --no-fuzzy-matching      Do not use fuzzy matching
    --keep-header            Keep the existing .po file header
    --no-obsolete            Remove obsolete message strings
    --no-wrap                Don't break long message lines
    --check                  Exit with error if .po files would change (dry-run)
    --timing                 Show timing information

How it works

  1. Walks the project tree using ignore (same engine as ripgrep)
  2. Extracts translatable strings from .py and .html/.txt templates in parallel using rayon
  3. Merges extracted strings with existing .po files, preserving translations
  4. Writes updated .po files

The extractor handles:

  • Python gettext(), ngettext(), pgettext(), npgettext() and the _() alias
  • Django template tags: {% trans %}, {% translate %}, {% blocktrans %}, {% blocktranslate %}
  • context "..." on both {% translate %} and {% blocktranslate %}, emitted as msgctxt
  • {% blocktrans trimmed %} whitespace collapsing
  • {% blocktrans %}...{% plural %}...{% endblocktrans %} plural forms
  • _("...") constants in block tags, variable expressions and filter arguments ({{ foo|default:_("bar") }})
  • Translators: comments, from # in Python and {# ... #} / {% comment %} in templates, written out as #. lines
  • Python implicit string concatenation (_("foo" "bar")) and triple-quoted strings
  • Template variable substitution, including filters and dotted lookups ({{ user.name|upper }} to %(user.name|upper)s)
  • Literal % escaping to %%
  • JavaScript sources under --domain djangojs
  • custom translation functions via --keyword, using xgettext's keywordspec syntax (name, name:2, name:1c,2, name:1,2)

Only arguments that are entirely string literals are extracted, matching xgettext: _(getattr(obj, 'verbose_name', label)) yields nothing, while _("a" "b") yields ab.

Entries that disappear from the source are kept as #~ obsolete blocks so existing translations survive, matching gettext. Pass --no-obsolete to drop them instead.

New .po files get the correct Plural-Forms for their locale, taken from a table generated out of Django's own shipped catalogs (98 locales; ja, ko and zh_* are nplurals=1, Russian and Polish get their 4-form rules, and so on). Unknown locales fall back to the base language, then to nplurals=2; plural=(n != 1);.

Per-app locale directories

By default everything is written to a single --locale-dir. Pass --per-app-locale to follow Django's layout instead: any directory named locale/ is treated as a locale root for the app containing it, and each file's messages go to the nearest enclosing one.

appA/locale/en/LC_MESSAGES/django.po   <- strings from appA/
appB/locale/en/LC_MESSAGES/django.po   <- strings from appB/
locale/en/LC_MESSAGES/django.po        <- everything else

No Django settings or DJANGO_SETTINGS_MODULE required — runs as a standalone CLI.

Pre-commit / Git hooks integration

Add to your pyproject.toml dev dependencies:

"django-makemessages-rs"

Then in your pre-commit script:

uv run django-makemessages-rs \
  -l en -l zh_Hant \
  --ignore .venv --ignore node_modules \
  --no-location --no-flags --sort-output \
  --no-fuzzy-matching --keep-header \
  --locale-dir locale

Testing

cargo test --release

There is also a differential suite that runs the real Django makemessages over the same fixtures and compares the extracted messages, so behavioral drift from Django gets caught:

python3 -m venv tests/differential/.venv
tests/differential/.venv/bin/pip install django django-extended-makemessages
cargo build --release
./tests/differential/run.sh

It needs GNU gettext (xgettext, msgmerge, msguniq, msgattrib) on PATH, plus django-extended-makemessages for the fixtures covering --keyword, --add-comments and --detect-aliases. Headers and #: locations are excluded from the comparison; everything else (msgid, msgid_plural, msgctxt, #. comments, ordering) must match exactly.

License

MIT

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

django_makemessages_rs-0.7.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.4 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ x86-64

django_makemessages_rs-0.7.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.3 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARM64

django_makemessages_rs-0.7.0-py3-none-macosx_11_0_arm64.whl (1.2 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

django_makemessages_rs-0.7.0-py3-none-macosx_10_12_x86_64.whl (1.3 MB view details)

Uploaded Python 3macOS 10.12+ x86-64

File details

Details for the file django_makemessages_rs-0.7.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for django_makemessages_rs-0.7.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f113b5b78284b3e9e739ae58cd355edb7762f0fc4db5e22af4f618a7c131ab99
MD5 fb910daad0d8e7674846ade13c6f5eae
BLAKE2b-256 bde39e37fe79d7b3e436705e9f378fbc898d2871ef42a1daa6008c6a3f1b179b

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_makemessages_rs-0.7.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on zxzinn/django-makemessages-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file django_makemessages_rs-0.7.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for django_makemessages_rs-0.7.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 0b38b88d4435a7b128fb8e371df24880d0b979e067c36fa7ee494c9276b55214
MD5 01e004c4c88ca498e7dce9025c400f12
BLAKE2b-256 07c08ba13b18581481036833de794398d386a0997bd9f2355a56057ffd8ebf9d

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_makemessages_rs-0.7.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on zxzinn/django-makemessages-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file django_makemessages_rs-0.7.0-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for django_makemessages_rs-0.7.0-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d2ec1ae046607f2fb858770b8f48a65c447b7a5df529948b969f1c6facb418e0
MD5 67ba322837555095ff2db92635fca260
BLAKE2b-256 5444f7657cfbd0e2e67bd36e4a4b4cb3feae55254a170445d1f1d0037fdc3085

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_makemessages_rs-0.7.0-py3-none-macosx_11_0_arm64.whl:

Publisher: release.yml on zxzinn/django-makemessages-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file django_makemessages_rs-0.7.0-py3-none-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for django_makemessages_rs-0.7.0-py3-none-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 fd7d660b433a72ba08e85b6a74ad06913198ed6237db305d80be017fd4e673a2
MD5 dad45ca2c11cf2790f8a99791167549a
BLAKE2b-256 b90897ebc52ea44912b01ff21409d2244109aafa7a8e5e3ee0b954ea4a9303be

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_makemessages_rs-0.7.0-py3-none-macosx_10_12_x86_64.whl:

Publisher: release.yml on zxzinn/django-makemessages-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.8.0

4 files

This release

0.7.0 This release

4 files

0.6.0

4 files

0.5.0

4 files

0.4.0

4 files

0.3.2

4 files

0.3.1

4 files

0.3.0

4 files

0.2.0

4 files

0.1.4

4 files

0.1.2

4 files

0.1.1

3 files

0.1.0

3 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page