Quick Start¶
This guide will walk you through translating your Django application in 5 minutes.
1. Configure API Key¶
Add your AI provider's API key to your settings:
import os
TRANSLATEBOT_API_KEY = os.getenv("OPENAI_API_KEY") # or ANTHROPIC_API_KEY, etc.
TRANSLATEBOT_MODEL = "gpt-4o-mini"
Popular models: gpt-4o-mini, gpt-4o, claude-3-5-sonnet-20241022, gemini/gemini-2.0-flash.
Environment Variables
Store your API key in an environment variable rather than hardcoding it in settings.
2. Configure Languages¶
Define the languages your app supports:
3. Create Translatable Strings¶
Mark strings for translation in your code:
from django.utils.translation import gettext as _
def my_view(request):
message = _("Welcome to our website!")
greeting = _("Hello, %(name)s!") % {'name': request.user.username}
return render(request, 'template.html', {'message': message})
4. Generate .po Files¶
Create message files for each language:
python manage.py makemessages -l de
python manage.py makemessages -l fr
python manage.py makemessages -l nl
Or all at once:
5. Translate Automatically¶
Now the magic happens! Run the translate command:
# Translate to all configured languages
python manage.py translate
# Or translate to a specific language
python manage.py translate --target-lang nl
Output
6. Compile Messages¶
Compile the translations so Django can use them:
Done!¶
Your app is now translated! Switch the language in your browser or use Django's language middleware to see the translations in action.
Preview First (Optional)¶
Want to see what will be translated before committing? Use dry-run mode:
This shows all translations without saving them.
Next Steps¶
- Learn about Configuration Options
- Explore PO File Translation in depth
- Set up Model Translation for database content