Skip to content

Commit

Permalink
feat: added support for translation in notifications (openedx#32626)
Browse files Browse the repository at this point in the history
  • Loading branch information
muhammadadeeltajamul authored Jul 4, 2023
1 parent 117539d commit ac5b087
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions openedx/core/djangoapps/notifications/base_notification.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""
Base setup for Notification Apps and Types.
"""
from django.utils.translation import gettext_lazy as _

from .utils import (
find_app_in_normalized_apps,
find_pref_in_normalized_prefs,
Expand All @@ -13,8 +15,8 @@
'name': 'new_comment_on_response',
'is_core': True,
'info': 'Comment on response',
'content_template': '<p><strong>{replier_name}</strong> replied on your response in '
'<strong>{post_title}</strong></p>',
'content_template': _('<{p}><{strong}>{replier_name}</{strong}> replied on your response in '
'<{strong}>{post_title}</{strong}></{p}>'),
'content_context': {
'post_title': 'Post title',
'replier_name': 'replier name',
Expand All @@ -30,8 +32,8 @@
'push': True,
'info': 'Comment on post',
'non-editable': ['web', 'email'],
'content_template': '<p><strong>{replier_name}</strong> replied on <strong>{author_name}</strong> response '
'to your post <strong>{post_title}</strong></p>',
'content_template': _('<{p}><{strong}>{replier_name}</{strong}> replied on <{strong}>{author_name}'
'</{strong}> response to your post <{strong}>{post_title}</{strong}></{p}>'),
'content_context': {
'post_title': 'Post title',
'author_name': 'author name',
Expand All @@ -48,8 +50,8 @@
'push': True,
'info': 'Response on post',
'non-editable': [],
'content_template': '<p><strong>{replier_name}</strong> responded to your '
'post <strong>{post_title}</strong></p>',
'content_template': _('<{p}><{strong}>{replier_name}</{strong}> responded to your '
'post <{strong}>{post_title}</{strong}></{p}>'),
'content_context': {
'post_title': 'Post title',
'replier_name': 'replier name',
Expand Down Expand Up @@ -282,9 +284,13 @@ def get_notification_content(notification_type, context):
"""
Returns notification content for the given notification type with provided context.
"""
html_tags_context = {
'strong': 'strong',
'p': 'p',
}
notification_type = NotificationTypeManager().notification_types.get(notification_type, None)
if notification_type:
notification_type_content_template = notification_type.get('content_template', None)
if notification_type_content_template:
return notification_type_content_template.format(**context)
return notification_type_content_template.format(**context, **html_tags_context)
return ''

0 comments on commit ac5b087

Please sign in to comment.