i18n: Mark notification bot message in notify_new_user for translation.

This commit is contained in:
Vishnu KS
2020-06-26 11:43:49 +00:00
committed by Tim Abbott
parent 544760daa7
commit ce6203906f
2 changed files with 27 additions and 14 deletions

View File

@@ -86,6 +86,7 @@ IGNORED_PHRASES = [
r"zulip_org_id", r"zulip_org_id",
r"admins", r"admins",
r"members", r"members",
r"signups",
# Placeholders # Placeholders
r"keyword", r"keyword",
r"streamname", r"streamname",

View File

@@ -33,6 +33,7 @@ from django.db.models import Count, Exists, F, Max, OuterRef, Q, Sum
from django.db.models.query import QuerySet 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 override as override_language
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from psycopg2.extras import execute_values from psycopg2.extras import execute_values
from psycopg2.sql import SQL from psycopg2.sql import SQL
@@ -341,12 +342,17 @@ def notify_new_user(user_profile: UserProfile) -> None:
# Send notification to realm signup notifications stream if it exists # Send notification to realm signup notifications stream if it exists
# Don't send notification for the first user in a realm # Don't send notification for the first user in a realm
if signup_notifications_stream is not None and user_count > 1: if signup_notifications_stream is not None and user_count > 1:
with override_language(user_profile.realm.default_language):
message = _("{user} just signed up for Zulip. (total: {user_count})").format(
user=f"@_**{user_profile.full_name}|{user_profile.id}**",
user_count=user_count
)
internal_send_stream_message( internal_send_stream_message(
user_profile.realm, user_profile.realm,
sender, sender,
signup_notifications_stream, signup_notifications_stream,
"signups", _("signups"),
f"@_**{user_profile.full_name}|{user_profile.id}** just signed up for Zulip. (total: {user_count})", message
) )
# We also send a notification to the Zulip administrative realm # We also send a notification to the Zulip administrative realm
@@ -354,12 +360,18 @@ def notify_new_user(user_profile: UserProfile) -> None:
try: try:
# Check whether the stream exists # Check whether the stream exists
signups_stream = get_signups_stream(admin_realm) signups_stream = get_signups_stream(admin_realm)
with override_language(admin_realm.default_language):
# We intentionally use the same strings as above to avoid translation burden.
message = _("{user} just signed up for Zulip. (total: {user_count})").format(
user=f"{user_profile.full_name} <`{user_profile.email}`>",
user_count=user_count
)
internal_send_stream_message( internal_send_stream_message(
admin_realm, admin_realm,
sender, sender,
signups_stream, signups_stream,
user_profile.realm.display_subdomain, user_profile.realm.display_subdomain,
f"{user_profile.full_name} <`{user_profile.email}`> just signed up for Zulip! (total: **{user_count}**)", message
) )
except Stream.DoesNotExist: except Stream.DoesNotExist: