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

Add --no-untranslated to also fail when a message has an empty msgstr, which catches strings that were extracted but never translated:

django-makemessages-rs -l en -l zh_Hant --locale-dir locale \
  --check --no-untranslated

--dry-run computes everything and reports, but never touches the tree.

Compiling to .mo

--compile runs msgfmt --check-format over each .po it wrote, the same way Django's compilemessages does, so a single invocation can refresh and compile the catalogs:

django-makemessages-rs -l en -l zh_Hant --locale-dir locale --compile

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)
    --dry-run                Compute everything but leave the tree untouched
    --no-untranslated        Exit with error if any message is untranslated
    --compile                Also compile .po to .mo afterwards (needs msgfmt)
    --width <WIDTH>          Wrap at this column instead of 80 (0 disables)
    --force-po               Write the .po even when it holds no messages
    --no-flag <FLAG>         Remove only this flag from '#,' lines (repeatable)
    --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.8.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.8.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.8.0-py3-none-macosx_11_0_arm64.whl (1.2 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

django_makemessages_rs-0.8.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.8.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for django_makemessages_rs-0.8.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5c958b54611f34eaf8db768d49488ca17842c930e5c145a905c70423ea70e077
MD5 a044e3474d1f2bb540e633938ae71de2
BLAKE2b-256 2f08523378e958d98dbe658083cd4a806efc03656a4f0d54bad27783dbcd5730

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for django_makemessages_rs-0.8.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 3b2aa8d575aa0f1d2630c9588c01e42b36519a01bb92e769b951f8a126c79146
MD5 bd7046ba0dc3a3f36a7eb0d7f9438509
BLAKE2b-256 972c05363fb2ad094dcd00e2319e8d1a40239e23b20875f77a04cacdbc459b6a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for django_makemessages_rs-0.8.0-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 032a1b57d0a05fe60b1a5cad7bdb16c6e345861f6f098d7c443cc123fdbdc352
MD5 665261065636fddb40e3272b799bc5c7
BLAKE2b-256 10a4ec5f31155a63b16b774abdb5b50f48c818de15ab6dcd034c7ca89981ba58

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for django_makemessages_rs-0.8.0-py3-none-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 ee15ef33c59daea7bad732d1bc9ccec97235feead2461678a6d7951b5c64dda5
MD5 8f4c67e29f3d8c774847787e59e16fc1
BLAKE2b-256 dab8185f3088fa75dff31369062ed2092728f67060bfc55591add2c9337744f7

See more details on using hashes here.

Provenance

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

This release

0.8.0 This release

4 files

0.7.0

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