← Back to Chapters

Internationalization (i18n) & Localization (l10n) in Django

? Internationalization (i18n) & Localization (l10n) in Django

? Quick Overview

Internationalization (i18n) prepares your application for adaptation to different languages, regions, and cultures, while Localization (l10n) adapts the application to a specific locale. This guide explains how to implement both in Django.

? Key Concepts

  • i18n: Preparing an app for multiple languages
  • l10n: Adapting content for a specific locale
  • Django Support: Built-in translation and formatting tools

? Syntax & Theory

? What is Internationalization (i18n)?

i18n is the process of designing an application to easily support multiple languages, formats, and cultural conventions.

? What is Localization (l10n)?

l10n involves adapting the application’s content and formats for a specific locale.

⚙️ Django Configuration

? View Code Example
# Enable i18n and l10n in Django settings
USE_I18N = True
USE_L10N = True
USE_TZ = True

LANGUAGES = [
('en', 'English'),
('es', 'Spanish'),
('fr', 'French'),
('de', 'German'),
]

LOCALE_PATHS = [
os.path.join(BASE_DIR, 'locale'),
]
? View Code Example
# Mark strings for translation in views
from django.utils.translation import gettext as _

def my_view(request):
message = _("Welcome to our website!")
return render(request, 'index.html', {'message': message})
? View Code Example
# Generate translation files
django-admin makemessages -l es
? View Code Example
# Spanish translation file
msgid "Welcome to our website!"
msgstr "¡Bienvenido a nuestro sitio web!"
? View Code Example
# Compile translations for runtime
django-admin compilemessages

? Localization Example

? View Code Example
# Localize date formatting in templates
{% load l10n %}
{% localize on %}{{ some_date }}{% endlocalize %}
? View Code Example
# Enable LocaleMiddleware
'django.middleware.locale.LocaleMiddleware'

? Interactive Simulator

Click a language button below to see how Django (simulated via JS) changes the text translation and date/currency formats.

Translated String (gettext)
Welcome to our website!

Localized Date (l10n)
Loading...
Localized Currency (l10n)
Loading...

? Use Cases

  • Multilingual websites
  • Global SaaS platforms
  • Region-specific formatting
  • International e-commerce

✅ Tips & Best Practices

  • Mark translatable strings early
  • Test UI with different languages
  • Adapt date, time, and currency formats
  • Provide a language switcher

? Try It Yourself

  • Enable i18n in a Django project
  • Add Spanish translations
  • Test formatting across locales