Internationalization (i18n) is the process of designing software to be adapted to various languages and regions without code changes, while localization (L10n) is adapting internationalized software for a specific locale. Localization involves more than just translation and includes adapting number, date, and currency formats. Django supports i18n/L10n through settings, middleware, template and view translation markers, locale directories containing .po translation files, and compilation to .mo files. Custom locales can also be activated.
2. Internationalization (i18n)
” Internationalization is the process of designing a software
application so that it can be adapted to various languages and
regions without engineering changes. “ Wikipedia
➡ Make an application language agnostic
3. Localization (L10n)
” Localization is the process of adapting internationalized
software for a specific region or language by adding locale-
specific components and translating text. “ Wikipedia
➡ Adapting an application for a specific language (aka locale)
4. It is is not only about language translation
• Number format
• Date/Time
• Sort orders
• Units and conversion
• Currency
• Paper size
14. settings.py
# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'
# If you set this to False, Django will make some optimizations so as
# not to load the internationalization machinery.
USE_I18N = True
# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale
USE_L10N = True
15. Detects your locale from the HTTP request
settings.py
MIDDLEWARE_CLASSES = (
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
)
16. settings.py
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'WebDirectory',
'HelloLocale',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
)
21. Create a locale
• Create a locale directory in the app
•
$ cd HelloLocale
The locale identifier
$ mkdir Locale
$ django-admin.py makemessages -l fr
➡ Generates a .po file