PO File Translation¶
TranslateBot Django automatically translates your Django .po (gettext) files, which are the standard way Django handles internationalization.
How It Works¶
- Scans your project for
.pofiles in:LOCALE_PATHSdirectories- App-specific
locale/directories - Default
locale/directory
- Identifies untranslated entries (empty
msgstr) - Sends messages to the AI model with instructions to preserve formatting
- Updates the
.pofile with translations - Skips obsolete entries and third-party packages automatically
Basic Usage¶
Translate to a Specific Language¶
Translate to All Languages¶
If you have LANGUAGES defined in settings:
This translates to all languages except English (the source).
Preview Mode¶
See what would be translated without making API calls or changes:
Dry Run Output
Dry run mode skips the LLM API entirely, so there are no costs. It shows you exactly which strings need translation before you commit.
Re-translate Existing Entries¶
By default, only empty entries are translated. To re-translate everything:
Warning
This will replace all existing translations. Consider using --dry-run first.
Placeholder Preservation¶
TranslateBot preserves all Django placeholders:
| Type | Example | Preserved |
|---|---|---|
| Named | %(name)s, %(count)d |
Yes |
| Positional | %s, %d |
Yes |
| Format strings | {0}, {name} |
Yes |
| HTML tags | <strong>, <a href="..."> |
Yes |
| Line breaks | \n |
Yes |
Example¶
Source:
Translated (Dutch):
Intelligent Batching¶
TranslateBot groups strings into batches based on the AI model's token limits. This:
- Maximizes efficiency by reducing API calls
- Handles large projects with thousands of strings
- Automatically adjusts batch size based on content length
Workflow Example¶
# 1. Mark strings in your code
from django.utils.translation import gettext as _
message = _("Welcome to %(site_name)s!")
# 2. Generate .po files
python manage.py makemessages -l de -l fr -l nl
# 3. Preview translations
python manage.py translate --dry-run
# 4. Apply translations
python manage.py translate
# 5. Compile for use
python manage.py compilemessages
Best Practices¶
Use Dry Run First
Always preview translations with --dry-run before applying them to catch any issues.
Commit Before Translating
Commit your .po files to version control before running translations, so you can easily revert if needed.
Review Translations
While AI translations are generally good, consider having a native speaker review critical user-facing text.
Next Steps¶
- Learn about Model Translation for database content
- See all Command Options