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
Django i18n: Built-In Translation for Python Web Apps
Django ships with a full internationalization framework powered by GNU gettext.
- Runtime
- GNU gettext
- Sync
- lefine
django.utils.translation
01views.py
# views.pyfrom django.utils.translation import gettext as _from django.utils.translation import ngettextdef welcome(request): output = _("Welcome to our site") count = 5 output += ngettext( "%(count)d item", "%(count)d items", count ) % {"count": count} return HttpResponse(output)02settings.py
# settings.pyLANGUAGE_CODE = 'en'USE_I18N = TrueLANGUAGES = [ ('en', 'English'), ('fr', 'French'), ('de', 'German'),]_("Welcome to our site")Welcome to our site
Django i18n in Practice
Use gettext functions in views and ngettext for plurals, then configure LANGUAGES in settings.py to define your supported locales.
Django i18n Features
- GNU gettext integration with _() and gettext_lazy() translation functions
- .po/.mo file workflow with makemessages and compilemessages commands
- Template tags {% translate %} and {% blocktranslate %} for in-template translations
- Pluralization support with ngettext and {% blocktranslate 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 zoneinfo
Related Guides
- Ruby i18nCompare Django gettext with Ruby on Rails YAML-based i18n for server-side translation patterns.
- JavaScript i18nExplore JavaScript Intl API for client-side formatting alongside your Django backend.
- TMS ComparisonsCompare translation management platforms to find the best fit for your Django project.
Get started
Start free.
Start Django Localization Today
Manage your Django translations with AI-powered workflows and CDN delivery.