From 3e14434f9e9baf8bcda2f4466e27f418474cf64b Mon Sep 17 00:00:00 2001 From: AarDG10 Date: Fri, 13 Mar 2026 10:43:53 +0530 Subject: [PATCH] fix: add fallback to also check for translation w/ html tags Adds a fallback to check for translations w/ and w/o HTML tags. --- frappe/utils/translations.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/frappe/utils/translations.py b/frappe/utils/translations.py index 93f739a39c..4c9bc3f4b2 100644 --- a/frappe/utils/translations.py +++ b/frappe/utils/translations.py @@ -16,6 +16,8 @@ def _(msg: str, lang: str | None = None, context: str | None = None) -> str: if not lang: lang = frappe.local.lang + all_translations = get_all_translations(lang) + non_translated_string = msg if is_html(msg): @@ -24,17 +26,23 @@ def _(msg: str, lang: str | None = None, context: str | None = None) -> str: # msg should always be unicode msg = frappe.as_unicode(msg).strip() - translated_string = "" + msg_with_html = frappe.as_unicode(non_translated_string).strip() + msg_list = [msg, msg_with_html] - all_translations = get_all_translations(lang) - if context: - string_key = f"{msg}:{context}" - translated_string = all_translations.get(string_key) + for msg in msg_list: + translated_string = "" - if not translated_string: - translated_string = all_translations.get(msg) + if context: + string_key = f"{msg}:{context}" + translated_string = all_translations.get(string_key) - return translated_string or non_translated_string + if not translated_string: + translated_string = all_translations.get(msg) + + if translated_string: + return translated_string + + return non_translated_string def _lt(msg: str, lang: str | None = None, context: str | None = None):