I wrote my templates in ENGLISH by using {% trans %} inside.
I decided to translate that into French, so I put that in the settings :
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'debug_toolbar.middleware.DebugToolbarMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
LANGUAGES = (
('en', _('English')),
('fr', _('French')),
)
LANGUAGE_CODE = 'fr'
LOCALE_PATHS = (
os.path.join(BASE_DIR, 'locale'),
)
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
Then I used makemessages and compilemessages to generated translated strings. And this worked fine ! My website is in French.
But now I would like to get back my site to be in English, So I just change LANGUAGE_CODE to :
LANGUAGE_CODE = 'en'
But my website is still in French ! Even the django-debug-bar is still in French.
The only workaround I found is to comment out the french in LANGUAGES :
LANGUAGES = (
('en', _('English')),
# ('fr', _('French')),
)
Why LANGUAGE_CODE = 'en' does not work ?
You need to comment or disable
'django.middleware.locale.LocaleMiddleware',
in settings.py.
This middleware handles the choice of the language from the request parameters.
Translation documentation :
https://docs.djangoproject.com/en/1.11/topics/i18n/translation/#how-django-discovers-language-preference
Middleware documentation :
https://docs.djangoproject.com/en/1.11/ref/middleware/#module-django.middleware.locale
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With