Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
typing: Access LANGUAGE_CODE via `django.utils.translation.get_language`.
Zixuan James Li27be27560b54
diff --git a/zerver/forms.py b/zerver/forms.pyindex 79b9c30f990..36702761baf 100644--- a/zerver/forms.py+++ b/zerver/forms.py@@ -13,6 +13,7 @@ from django.core.validators import validate_emailfrom django.http import HttpRequestfrom django.urls import reversefrom django.utils.http import urlsafe_base64_encode+from django.utils.translation import get_languagefrom django.utils.translation import gettext as _from django.utils.translation import gettext_lazyfrom markupsafe import Markup as mark_safe@@ -382,7 +383,8 @@ class ZulipPasswordResetForm(PasswordResetForm):)if active_accounts_in_other_realms:context["active_accounts_in_other_realms"] = active_accounts_in_other_realms- language = request.LANGUAGE_CODE+ language = get_language()+send_email("zerver/emails/password_reset",to_emails=[email],diff --git a/zerver/tests/test_signup.py b/zerver/tests/test_signup.pyindex c7e00ffe146..ab81bc9abc3 100644--- a/zerver/tests/test_signup.py+++ b/zerver/tests/test_signup.py@@ -14,7 +14,9 @@ from django.core.exceptions import ValidationErrorfrom django.http import HttpRequest, HttpResponsefrom django.test import Client, override_settingsfrom django.urls import reverse+from django.utils import translationfrom django.utils.timezone import now as timezone_now+from django.utils.translation import gettext as _from confirmation import settings as confirmation_settingsfrom confirmation.models import (@@ -378,9 +380,10 @@ class PasswordResetTest(ZulipTestCase):[message] = outboxself.assertEqual(self.email_envelope_from(message), settings.NOREPLY_EMAIL_ADDRESS)+ # The email might be sent in different languages for i18n testingself.assertRegex(self.email_display_from(message),- rf"^Zulip Account Security <{self.TOKENIZED_NOREPLY_REGEX}>\Z",+ rf'^{_("Zulip Account Security")} <{self.TOKENIZED_NOREPLY_REGEX}>\Z',)self.assertIn(f"{subdomain}.testserver", message.extra_headers["List-Id"])@@ -659,6 +662,23 @@ class PasswordResetTest(ZulipTestCase):self.assertNotIn("reset your password", body)self.assertNotIn("deactivated", body)+ def test_wrong_subdomain_i18n(self) -> None:+ user_profile = self.example_user("hamlet")+ email = user_profile.delivery_email++ # Send a password reset request with a different language to a wrong subdomain+ result = self.client_post(+ "/accounts/password/reset/",+ {"email": email},+ HTTP_ACCEPT_LANGUAGE="de",+ subdomain="lear",+ )+ self.assertEqual(result.status_code, 302)++ with translation.override("de"):+ body = self.get_reset_mail_body("lear")+ self.assertIn("hat ein neues Passwort", body)+def test_invalid_subdomain(self) -> None:email = self.example_email("hamlet")diff --git a/zerver/views/registration.py b/zerver/views/registration.pyindex 6d152c3e663..ce051bd612c 100644--- a/zerver/views/registration.py+++ b/zerver/views/registration.py@@ -12,6 +12,7 @@ from django.db.models import Qfrom django.http import HttpRequest, HttpResponse, HttpResponseRedirectfrom django.shortcuts import redirect, renderfrom django.urls import reverse+from django.utils.translation import get_languagefrom django.utils.translation import gettext as _from django_auth_ldap.backend import LDAPBackend, _LDAPUser@@ -581,7 +582,7 @@ def send_confirm_registration_email("zerver/emails/confirm_registration",to_emails=[email],from_address=FromAddress.tokenized_no_reply_address(),- language=request.LANGUAGE_CODE if request is not None else None,+ language=get_language() if request is not None else None,context={"create_realm": (realm is None),"activate_url": activation_url,