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
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'),
]Related Guides
Ruby i18n
Compare Django gettext with Ruby on Rails YAML-based i18n for server-side translation patterns.
JavaScript i18n
Explore JavaScript Intl API for client-side formatting alongside your Django backend.
TMS Comparisons
Compare translation management platforms to find the best fit for your Django project.
Start Django Localization Today
Manage your Django .po file translations with AI-powered workflows, CLI sync, and CDN delivery under 50ms.