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

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
cargo build --release
./tests/differential/run.sh

It needs GNU gettext (xgettext, msgmerge, msguniq, msgattrib) on PATH. 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.6.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.6.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.6.0-py3-none-macosx_11_0_arm64.whl (1.2 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

django_makemessages_rs-0.6.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.6.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for django_makemessages_rs-0.6.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 81da9cedf4d5bbf4566f165a901592cf9c6000d386630de172fd0474a495e242
MD5 5dbe1b49d5fe4c0d3dc3bca081d1059b
BLAKE2b-256 ada4ddd6478314d2fffe811cecf09a1e4d64973cc967b56d878393718cae0980

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_makemessages_rs-0.6.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.6.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for django_makemessages_rs-0.6.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 9d20229c71befad8acc5a5e066d85fb5fad83c6f2820ce8da3ef5101a4d32872
MD5 48cb29391f994337580b4526bec84c8f
BLAKE2b-256 54d8c27938e39b17c98a3601418c4264abfa08fb07a2169812487fd98e159a18

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_makemessages_rs-0.6.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.6.0-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for django_makemessages_rs-0.6.0-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1bd1c3baf31bee3328940ddf05945798fcac88de447db2760770e64b8879c17a
MD5 056b8554c44670ecb795a83c67077e21
BLAKE2b-256 cfa6a5a50bbcbdfad3415b7811d1f5cc2798483bfa2e0985ad1b7d5d06fa9bfd

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_makemessages_rs-0.6.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.6.0-py3-none-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for django_makemessages_rs-0.6.0-py3-none-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 7394fb95eaf41da4a276b99a020837163113bb5dcbf35d78a3ccf9980daf1a04
MD5 57c5887375fabef4a045212157cfade9
BLAKE2b-256 93687412f5b34a9b5f3fbf5d7170e77f76698a68868655cb275671b0db06b958

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_makemessages_rs-0.6.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

0.7.0

4 files

This release

0.6.0 This release

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