Skip to content

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:

settings.py
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:

settings.py
LANGUAGES = [
    ('en', 'English'),
    ('de', 'German'),
    ('fr', 'French'),
    ('nl', 'Dutch'),
]

3. Create Translatable Strings

Mark strings for translation in your code:

views.py
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:

python manage.py makemessages -l de -l fr -l nl

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

Translating to Dutch (nl)...
Found 42 strings to translate
Translating batch 1/2...
Translating batch 2/2...
Successfully translated 42 strings

6. Compile Messages

Compile the translations so Django can use them:

python manage.py compilemessages

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:

python manage.py translate --target-lang nl --dry-run

This shows all translations without saving them.

Next Steps