Skip to content

Add i18n support for parser/lexer/schema error messages#1

Merged
mpasternak merged 3 commits into
masterfrom
feature-i18n
May 13, 2026
Merged

Add i18n support for parser/lexer/schema error messages#1
mpasternak merged 3 commits into
masterfrom
feature-i18n

Conversation

@mpasternak
Copy link
Copy Markdown
Member

Summary

Adds Django i18n support for every user-facing error message produced by DjangoQL — lexer, parser, schema validator, suggestions API view, and the small `error_message.html` template. Ships translation catalogs for 11 locales.

  • All error strings in `lexer.py`, `parser.py`, `schema.py`, `views.py` and `exceptions.py` are wrapped with `gettext_lazy`. Multi-variable messages use named `.format()` placeholders so translators can reorder freely (important for Polish, Russian, Japanese, etc. where word order differs from English).
  • `templates/djangoql/error_message.html` now uses `{% trans %}` for the "DjangoQL syntax help" label.
  • 11 translation catalogs under `djangoql/locale//LC_MESSAGES/`: `pl` is hand-written native-quality Polish (used as the canary by the i18n tests); `de`, `fr`, `es`, `ru`, `uk`, `pt_BR`, `it`, `nl`, `ja`, `zh_Hans` are auto-translated seeds with `# Auto-translated. Review by a native speaker welcome — open a PR.` markers in their `.po` headers.
  • New test module `test_project/core/tests/test_i18n.py` (5 tests) asserts that error messages translate under `override('pl')` and stay English otherwise.
  • CI: `sudo apt-get install -y gettext` step added, and `django-admin compilemessages` runs in the `djangoql/` working directory before tests — this also validates every `.po` on every matrix entry.
  • `MANIFEST.in` updated to ship `.po` and `.mo` files. README gets a new "Internationalization" section. CHANGES.rst gets an "Unreleased" entry.

If a translation is missing for a string or locale, gettext falls back to the English source — so this is a strictly additive change.

Test plan

  • `python test_project/manage.py test core.tests` — 50 tests pass (45 existing + 5 new)
  • `flake8 djangoql test_project` — clean
  • `isort --diff -c .` — clean
  • `msgfmt --check-format` on all 11 `.po` files — clean (named-placeholder and `%`-format integrity verified)
  • Manual: `override('pl')` produces "Niedozwolony znak '@'" instead of "Illegal character '@'"
  • Manual: `override('pl')` then `str(StrField.value_types_description)` returns "łańcuchami znaków"
  • CI green across the full Django × Python matrix (will verify post-push)

Notes for reviewers

  • The Polish locale is the only one with native-speaker quality. The other 10 are best-effort auto-translations intended as seeds for community contributions — feel free to merge as-is or wait for native review per locale. Each `.po` is independently replaceable without touching code.
  • Version is intentionally left as `0.19.1` and CHANGES.rst uses an `Unreleased` header so the maintainer can assign the actual version on merge.

🤖 Generated with Claude Code

mpasternak and others added 3 commits May 13, 2026 22:29
Wrap all user-facing error strings emitted by lexer.py, parser.py,
schema.py, views.py and exceptions.py with gettext_lazy so they can
be translated per the active Django locale. Multi-variable messages
use named .format() placeholders for translator-friendly reordering.

Translate the "DjangoQL syntax help" label in
templates/djangoql/error_message.html.

Ship translation catalogs for 11 locales: pl (hand-written, native),
plus de, fr, es, ru, uk, pt_BR, it, nl, ja, zh_Hans as auto-translated
seeds marked for native-speaker review.

Add an i18n test module that asserts error messages are translated
under override('pl') and stay English under override('en').

CI: install gettext and run `django-admin compilemessages` in the
djangoql/ directory before tests, so .po files are validated on
every matrix entry.

Update README with an Internationalization section and add an entry
to CHANGES.rst.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Add trailing commas after the last (implicit-concat) string literal
inside five multi-line `_(...)` gettext calls in schema.py. flake8-commas
(which CI runs but my initial local check did not) requires a trailing
comma whenever a function call's closing paren sits on its own line,
regardless of arity.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Adds a pre-commit configuration that runs flake8 (with the same
flake8-builtins / flake8-commas / flake8-print / flake8-quotes plugins
CI uses) and isort on staged files only. Catches the exact lint failures
that CI catches, before the commit lands, without rechecking the rest
of the repo on every commit.

Versions are bumped past requirements-dev.txt to install on modern
Python (3.10+); the rules enforced (C812, T2, A003, isort ordering) are
the same as the CI pins. The `exclude` mirrors setup.cfg.

Usage:
  pip install pre-commit && pre-commit install
  pre-commit run                # staged files (auto-runs on git commit)
  pre-commit run --all-files    # everything

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@mpasternak mpasternak merged commit 4f8d4f3 into master May 13, 2026
56 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant