Automating i18n in Django with Claude Code and GStack
Claude Code paired with the GStack skills package automates creating and updating translations in Django projects. The tool scans files, spots hardcoded strings, generates i18n keys, and compiles messages. The whole process takes minutes instead of hours of manual work, cutting down errors and token usage.
Setting Up Your Environment
Install Claude Code and the GStack package following their instructions. Activate the /qa skill for localization tasks. Make sure your settings.py has USE_I18N = True and a LANGUAGE_CODE set.
For new languages, add them to LANGUAGES:
LANGUAGES = [
('en', 'English'),
('ru', 'Russian'),
]
Real-World Example: Translating Updates
When adding text to a landing page, point the /qa skill to the changed files in your prompt. Example prompt:
Translate all changes in templates/landing.html to English. Create i18n keys, update .po files, and run compilemessages.
The AI analyzes the code and suggests a plan:
- Scan the file for static strings.
- Generate gettext keys (e.g.,
msgid "Welcome"→msgctxt "landing.welcome"). - Fill in translations in
django.po. - Compile with
python manage.py compilemessages.
Approve the plan, and it runs automatically.
Implementation Details
The skill automatically finds spots with _('text') or plain strings in templates and views. For multiple files, list them or specify a directory. Token savings come from pinpointing exact file paths.
Key benefits:
- Auto key generation: Avoids duplicates and conflicts.
- Context-aware translations: Considers the string's surroundings for accuracy.
- Seamless makemessages integration: No manual runs needed.
- Scalable: Works for projects with dozens of languages.
In a test case, processing took 5 minutes and ~10K tokens. Result: Ready-to-use locale/en/LC_MESSAGES/django.mo files with zero manual tweaks.
Optimizing the Workflow
Comparing Approaches
| Method | Time | Tokens | Quality |
|--------|------|--------|---------|
| Manual makemessages + poedit | 30-60 min | 0 | Average (human error) |
| Claude Code /qa | 5 min | 10K | High (context analysis) |
| Full AI (no paths) | 7 min | 15K | High |
Ideal for side projects or production with strict translation reviews.
Best Practices
- Specify the source language clearly:
from Russian to English. - Review the plan before approving.
- Integrate into CI/CD: Script with Claude API calls.
- Add context for tricky phrases:
translate landing page greeting. - Test rendering:
{% load i18n %} {{ _('key') }}.
Key Takeaways
- Automation cuts routine work by 90%, letting you focus on coding.
- The
/qaskill runs Django commands on its own. - Saves on translators for mid/senior devs.
- Scales to large projects with many locales.
- Still needs review for nuances (idioms, formatting).
— Editorial Team
No comments yet.