From bf64cb2d1cddde082686006575916edaded626a6 Mon Sep 17 00:00:00 2001 From: Eeshan Garg Date: Thu, 23 Sep 2021 18:21:26 -0400 Subject: [PATCH] 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. --- zerver/lib/actions.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/zerver/lib/actions.py b/zerver/lib/actions.py index 21a2e3dd70..1436f558aa 100644 --- a/zerver/lib/actions.py +++ b/zerver/lib/actions.py @@ -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,