mirror of
https://github.com/zulip/zulip.git
synced 2025-11-09 16:37:23 +00:00
topics: Fix translation issue with moved topic notifications.
Since the calls to the translation function `_()` are made outside of the `send_message_moved_breadcrumbs` function, these strings are translated outside of the `with override_language` block, leading to translated strings even when we don't intend them to be translated. We now use gettext_lazy with appropriate testing to avoid this.
This commit is contained in:
@@ -35,6 +35,7 @@ from django.db.models.query import QuerySet
|
|||||||
from django.utils.html import escape
|
from django.utils.html import escape
|
||||||
from django.utils.timezone import now as timezone_now
|
from django.utils.timezone import now as timezone_now
|
||||||
from django.utils.translation import gettext as _
|
from django.utils.translation import gettext as _
|
||||||
|
from django.utils.translation import gettext_lazy
|
||||||
from django.utils.translation import override as override_language
|
from django.utils.translation import override as override_language
|
||||||
from psycopg2.extras import execute_values
|
from psycopg2.extras import execute_values
|
||||||
from psycopg2.sql import SQL
|
from psycopg2.sql import SQL
|
||||||
@@ -6489,11 +6490,13 @@ def do_update_message(
|
|||||||
# Notify users that the topic was moved.
|
# Notify users that the topic was moved.
|
||||||
old_thread_notification_string = None
|
old_thread_notification_string = None
|
||||||
if send_notification_to_old_thread:
|
if send_notification_to_old_thread:
|
||||||
old_thread_notification_string = _("This topic was moved by {user} to {new_location}")
|
old_thread_notification_string = gettext_lazy(
|
||||||
|
"This topic was moved by {user} to {new_location}"
|
||||||
|
)
|
||||||
|
|
||||||
new_thread_notification_string = None
|
new_thread_notification_string = None
|
||||||
if send_notification_to_new_thread:
|
if send_notification_to_new_thread:
|
||||||
new_thread_notification_string = _(
|
new_thread_notification_string = gettext_lazy(
|
||||||
"This topic was moved here from {old_location} by {user}"
|
"This topic was moved here from {old_location} by {user}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -79,9 +79,18 @@ class EditMessageTestCase(ZulipTestCase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def prepare_move_topics(
|
def prepare_move_topics(
|
||||||
self, user_email: str, old_stream: str, new_stream: str, topic: str
|
self,
|
||||||
|
user_email: str,
|
||||||
|
old_stream: str,
|
||||||
|
new_stream: str,
|
||||||
|
topic: str,
|
||||||
|
language: Optional[str] = None,
|
||||||
) -> Tuple[UserProfile, Stream, Stream, int, int]:
|
) -> Tuple[UserProfile, Stream, Stream, int, int]:
|
||||||
user_profile = self.example_user(user_email)
|
user_profile = self.example_user(user_email)
|
||||||
|
if language is not None:
|
||||||
|
user_profile.default_language = language
|
||||||
|
user_profile.save(update_fields=["default_language"])
|
||||||
|
|
||||||
self.login(user_email)
|
self.login(user_email)
|
||||||
stream = self.make_stream(old_stream)
|
stream = self.make_stream(old_stream)
|
||||||
new_stream = self.make_stream(new_stream)
|
new_stream = self.make_stream(new_stream)
|
||||||
@@ -1286,7 +1295,13 @@ class EditMessageTest(EditMessageTestCase):
|
|||||||
|
|
||||||
def test_move_message_to_stream(self) -> None:
|
def test_move_message_to_stream(self) -> None:
|
||||||
(user_profile, old_stream, new_stream, msg_id, msg_id_lt) = self.prepare_move_topics(
|
(user_profile, old_stream, new_stream, msg_id, msg_id_lt) = self.prepare_move_topics(
|
||||||
"iago", "test move stream", "new stream", "test"
|
"iago",
|
||||||
|
"test move stream",
|
||||||
|
"new stream",
|
||||||
|
"test",
|
||||||
|
# Set the user's translation language to German to test that
|
||||||
|
# it is overridden by the realm's default language.
|
||||||
|
"de",
|
||||||
)
|
)
|
||||||
|
|
||||||
result = self.client_patch(
|
result = self.client_patch(
|
||||||
@@ -1296,6 +1311,7 @@ class EditMessageTest(EditMessageTestCase):
|
|||||||
"stream_id": new_stream.id,
|
"stream_id": new_stream.id,
|
||||||
"propagate_mode": "change_all",
|
"propagate_mode": "change_all",
|
||||||
},
|
},
|
||||||
|
HTTP_ACCEPT_LANGUAGE="de",
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assert_json_success(result)
|
self.assert_json_success(result)
|
||||||
|
|||||||
Reference in New Issue
Block a user