Reputation: 83
My website is not in English, but I want the Django admin to be shown only in English.
How can I force the Django admin to display in English regardless of LANGUAGE_CODE
settings?
Upvotes: 5
Views: 1457
Reputation: 51
For Django 2.0 :
from django.utils import translation
class AdminLocaleMiddleware:
def __init__(self, process_request):
self.process_request = process_request
def __call__(self, request):
if request.path.startswith('/admin'):
translation.activate("en")
request.LANGUAGE_CODE = translation.get_language()
response = self.process_request(request)
return response
Upvotes: 5
Reputation: 1951
As far as I know there is no out of the box settings for this functionality, but you can easily code it in a middleware. Add this code to a middleware.py file to one of your apps:
from django.utils import translation
class AdminLocaleMiddleware(object):
def process_request(self, request):
if request.path.startswith('/admin'):
translation.activate("en")
request.LANGUAGE_CODE = translation.get_language()
Add AdminLocaleMiddleware to your settings after LocaleMiddleware:
MIDDLEWARE_CLASSES = [
...
"django.middleware.locale.LocaleMiddleware",
"your_app.middleware.AdminLocaleMiddleware",
...
]
Upvotes: 9