From 88a8c2e8987f5da18b0c251f4dc7b76becfebcbe Mon Sep 17 00:00:00 2001 From: Egor fureunoir Gorbunov Date: Mon, 12 May 2025 10:16:31 +0300 Subject: [PATCH] Features: 1) Activate translation based on request locale in CustomLocaleCommonMiddleware; 2) Activate translation within GrapheneJWTAuthorizationMiddleware; Fixes: None; Extra: None; --- evibes/middleware.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/evibes/middleware.py b/evibes/middleware.py index 68e624fc..1ed9e89f 100644 --- a/evibes/middleware.py +++ b/evibes/middleware.py @@ -8,6 +8,7 @@ from django.core.exceptions import DisallowedHost from django.http import HttpResponseForbidden from django.middleware.common import CommonMiddleware from django.shortcuts import redirect +from django.utils import translation from rest_framework_simplejwt.authentication import JWTAuthentication from rest_framework_simplejwt.exceptions import InvalidToken from sentry_sdk import capture_exception @@ -28,6 +29,7 @@ class CustomCommonMiddleware(CommonMiddleware): class CustomLocaleCommonMiddleware(CommonMiddleware): def process_request(self, request): request.locale = get_language_from_header(request.headers.get("Accept-Language", "")) + translation.activate(request.locale) class GrapheneJWTAuthorizationMiddleware: @@ -61,6 +63,8 @@ class GrapheneLocaleMiddleware: selected_language = get_language_from_header(accept_language) request.locale = selected_language + translation.activate(request.locale) + return next(root, info, **args)