topics: Fix translation issue with resolve topic notifications.

In maybe_send_resolve_topic_notifications, since the calls to the
translation function `_()` are made outside of the `override_language`
block, the strings are not translated correctly.

This commit refactors the function to make sure that the translation
happens in the right block of code.

Fixes #19730.
This commit is contained in:
Eeshan Garg 2021-09-23 18:21:26 -04:00 committed by Tim Abbott
parent 10c47b5d6c
commit bf64cb2d1c
1 changed files with 11 additions and 7 deletions

View File

@ -5885,15 +5885,14 @@ def maybe_send_resolve_topic_notifications(
if old_topic.lstrip(RESOLVED_TOPIC_PREFIX) != new_topic.lstrip(RESOLVED_TOPIC_PREFIX):
return
if new_topic.startswith(RESOLVED_TOPIC_PREFIX) and not old_topic.startswith(
topic_resolved: bool = new_topic.startswith(RESOLVED_TOPIC_PREFIX) and not old_topic.startswith(
RESOLVED_TOPIC_PREFIX
):
notification_string = _("{user} has marked this topic as resolved.")
elif old_topic.startswith(RESOLVED_TOPIC_PREFIX) and not new_topic.startswith(
)
topic_unresolved: bool = old_topic.startswith(
RESOLVED_TOPIC_PREFIX
):
notification_string = _("{user} has marked this topic as unresolved.")
else:
) and not new_topic.startswith(RESOLVED_TOPIC_PREFIX)
if not topic_resolved and not topic_unresolved:
# If there's some other weird topic that does not toggle the
# state of "topic starts with RESOLVED_TOPIC_PREFIX", we do
# nothing. Any other logic could result in cases where we send
@ -5912,6 +5911,11 @@ def maybe_send_resolve_topic_notifications(
sender = get_system_bot(settings.NOTIFICATION_BOT, user_profile.realm_id)
user_mention = f"@_**{user_profile.full_name}|{user_profile.id}**"
with override_language(stream.realm.default_language):
if topic_resolved:
notification_string = _("{user} has marked this topic as resolved.")
elif topic_unresolved:
notification_string = _("{user} has marked this topic as unresolved.")
internal_send_stream_message(
sender,
stream,