Merge pull request #37979 from AarDG10/fix-translations
fix: add fallback to consider messages w/ html tags
This commit is contained in:
commit
a1018be4df
2 changed files with 22 additions and 8 deletions
|
|
@ -92,6 +92,12 @@ class TestTranslation(IntegrationTestCase):
|
|||
|
||||
self.assertTrue(_(source), target)
|
||||
|
||||
def test_html_message_translations(self):
|
||||
"""Test fallback for messages w/ HTML Tags"""
|
||||
message = "Hide descendant records of <b>For Value</b>."
|
||||
translated_message = "隐藏下层节点<b>值</b>"
|
||||
self.assertEqual(_(message, lang="zh"), translated_message)
|
||||
|
||||
|
||||
def get_translation_data():
|
||||
html_source_data = """<font color="#848484" face="arial, tahoma, verdana, sans-serif">
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue