Use request language code when available (#346)

Enables translation on the login page.
This commit is contained in:
Christopher C. Wells 2021-11-28 14:18:00 -05:00
parent 0250faec6e
commit 4920f4341b
1 changed files with 11 additions and 4 deletions

View File

@ -47,13 +47,20 @@ class UserLanguageMiddleware:
def __call__(self, request): def __call__(self, request):
user = request.user user = request.user
if hasattr(user, 'settings'): if hasattr(user, 'settings') and user.settings.language:
# Set the custom user language before generating the response. language = user.settings.language
translation.activate(user.settings.language) elif request.LANGUAGE_CODE:
language = request.LANGUAGE_CODE
else:
language = settings.LANGUAGE_CODE
if user.settings.language == 'en-US': if language:
if language == 'en-US':
update_en_us_date_formats() update_en_us_date_formats()
# Set the language before generating the response.
translation.activate(language)
response = self.get_response(request) response = self.get_response(request)
# Deactivate the translation before the response is sent so it not # Deactivate the translation before the response is sent so it not