mirror of https://github.com/snachodog/mybuddy.git
parent
462459964c
commit
c28620b3d8
|
@ -3,7 +3,7 @@ import time
|
||||||
import pytz
|
import pytz
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.utils import timezone
|
from django.utils import timezone, translation
|
||||||
from django.conf.locale.en import formats as formats_en_us
|
from django.conf.locale.en import formats as formats_en_us
|
||||||
|
|
||||||
|
|
||||||
|
@ -47,10 +47,20 @@ class UserLanguageMiddleware:
|
||||||
|
|
||||||
def __call__(self, request):
|
def __call__(self, request):
|
||||||
user = request.user
|
user = request.user
|
||||||
if hasattr(user, 'settings') and user.settings.language == 'en-US':
|
if hasattr(user, 'settings'):
|
||||||
|
# Set the custom user language before generating the response.
|
||||||
|
translation.activate(user.settings.language)
|
||||||
|
|
||||||
|
if user.settings.language == 'en-US':
|
||||||
update_en_us_date_formats()
|
update_en_us_date_formats()
|
||||||
|
|
||||||
return self.get_response(request)
|
response = self.get_response(request)
|
||||||
|
|
||||||
|
# Deactivate the translation before the response is sent so it not
|
||||||
|
# reused in other threads.
|
||||||
|
translation.deactivate()
|
||||||
|
|
||||||
|
return response
|
||||||
|
|
||||||
|
|
||||||
class UserTimezoneMiddleware:
|
class UserTimezoneMiddleware:
|
||||||
|
|
Loading…
Reference in New Issue