Skip to content

Commit

Permalink
improve the usage of Babel in multilingual contexts to convert dates …
Browse files Browse the repository at this point in the history
…& times [NHUB-182] (superdesk#676)

* improve the usage of Babel in multilingual contexts to convert dates & times [NHUB-182]

* minor change

* remove unused imports
  • Loading branch information
devketanpro authored Dec 1, 2023
1 parent 0672a49 commit 63ec996
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
17 changes: 9 additions & 8 deletions newsroom/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from superdesk import get_resource_service
from flask import current_app, render_template, url_for
from flask_babel import gettext
from flask_babel import gettext, force_locale
from flask_mail import Attachment, Message
from jinja2 import TemplateNotFound
from newsroom.auth import get_company
Expand Down Expand Up @@ -204,13 +204,14 @@ def send_template_email(

try:
set_template_locale(language)
send_email(
to=group["emails"],
subject=subject,
text_body=render_template(group["text_template"], **template_kwargs),
html_body=render_template(group["html_template"], **template_kwargs),
**kwargs,
)
with force_locale(language):
send_email(
to=group["emails"],
subject=subject,
text_body=render_template(group["text_template"], **template_kwargs),
html_body=render_template(group["html_template"], **template_kwargs),
**kwargs,
)
finally:
set_template_locale()

Expand Down
3 changes: 1 addition & 2 deletions newsroom/template_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from superdesk.text_utils import get_text, get_word_count, get_char_count
from superdesk.utc import utcnow
from datetime import datetime
from newsroom.template_loaders import get_template_locale

from newsroom.user_roles import UserRole

Expand All @@ -24,7 +23,7 @@


def get_client_format(key) -> Optional[str]:
locale = str(get_template_locale() or get_locale())
locale = str(get_locale())
try:
return app.config["CLIENT_LOCALE_FORMATS"][locale][key]
except KeyError:
Expand Down

0 comments on commit 63ec996

Please sign in to comment.