Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
users,settings: add custom language middleware
- Loading branch information
Showing
5 changed files
with
35 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from django.conf import settings | ||
from django.utils import translation | ||
|
||
|
||
class SetUserLanguageCookieMiddleware: | ||
def __init__(self, get_response): | ||
self.get_response = get_response | ||
|
||
def __call__(self, request): | ||
response = self.get_response(request) | ||
cookie = request.COOKIES.get(settings.LANGUAGE_COOKIE_NAME) | ||
if hasattr(request.user, "language"): | ||
translation.activate(request.user.language) | ||
if cookie != request.user.language: | ||
response.set_cookie( | ||
settings.LANGUAGE_COOKIE_NAME, request.user.language | ||
) | ||
return response |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
### Added | ||
|
||
- custom middleware for user language | ||
|
||
### Fixed | ||
|
||
- language not changing to user preference after login |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters