Skip to content
Django i18n

Django i18n: Built-In Translation for Python Web Apps

Django ships with a full internationalization framework powered by GNU gettext. Mark strings for translation in views, models, and templates using gettext functions and template tags. Django compiles .po files into .mo binaries for fast lookup, and its middleware automatically activates the right locale based on URL prefixes, cookies, or browser headers.

Django i18n Features

GNU gettext integration with _() and gettext_lazy() translation functions
.po/.mo file workflow with makemessages and compilemessages commands
Template tags {% trans %} and {% blocktrans %} for in-template translations
Pluralization support with ngettext and {% blocktrans count %}
Lazy translation with gettext_lazy() for model fields and form labels
LocaleMiddleware for automatic language detection from URLs, cookies, and headers
i18n_patterns for locale-prefixed URL routing (e.g., /en/about, /fr/about)
Form and model field localization for dates, numbers, and currencies
Timezone-aware datetime handling with USE_TZ and pytz integration

Django i18n in Practice

Use gettext functions in views and ngettext for plurals, then configure LANGUAGES in settings.py to define your supported locales.

# views.py
from django.utils.translation import gettext as _
from django.utils.translation import ngettext

def welcome(request):
    output = _("Welcome to our site")
    count = 5
    output += ngettext(
        "%(count)d item",
        "%(count)d items",
        count
    ) % {"count": count}
    return HttpResponse(output)

# settings.py
LANGUAGE_CODE = 'en'
USE_I18N = True
LANGUAGES = [
    ('en', 'English'),
    ('fr', 'French'),
    ('de', 'German'),
]

Start Django Localization Today

Manage your Django .po file translations with AI-powered workflows, CLI sync, and CDN delivery under 50ms.