From dadf822152e9a77921bb225be888a8e1a95e0b11 Mon Sep 17 00:00:00 2001
From: Raffael Meyer <14891507+barredterra@users.noreply.github.com>
Date: Tue, 7 Apr 2026 21:09:56 +0200
Subject: [PATCH] fix(Translation): don't remove HTML from source_text (#33558)
---
.../doctype/translation/test_translation.py | 106 +++++++++---------
.../core/doctype/translation/translation.py | 10 +-
frappe/utils/html_utils.py | 2 +-
frappe/utils/translations.py | 4 -
4 files changed, 59 insertions(+), 63 deletions(-)
diff --git a/frappe/core/doctype/translation/test_translation.py b/frappe/core/doctype/translation/test_translation.py
index 7a28d068d3..0da71d3dc8 100644
--- a/frappe/core/doctype/translation/test_translation.py
+++ b/frappe/core/doctype/translation/test_translation.py
@@ -16,16 +16,20 @@ class TestTranslation(IntegrationTestCase):
clear_cache()
def test_doctype(self):
- translation_data = get_translation_data()
- for lang, (source_string, new_translation) in translation_data.items():
+ doctype = "Translation"
+ meta = frappe.get_meta(doctype)
+ source_string = meta.get_label("translated_text")
+
+ for lang in ["de", "bs", "zh", "hr", "en", "sv"]:
frappe.local.lang = lang
- original_translation = _(source_string)
+ original_translation = _(source_string, context=doctype)
+ new_translation = f"{original_translation} Customized"
- docname = create_translation(lang, source_string, new_translation)
- self.assertEqual(_(source_string), new_translation)
+ docname = create_translation(lang, source_string, new_translation, context=doctype)
+ self.assertEqual(_(source_string, context=doctype), new_translation)
- frappe.delete_doc("Translation", docname)
- self.assertEqual(_(source_string), original_translation)
+ frappe.delete_doc(doctype, docname)
+ self.assertEqual(_(source_string, context=doctype), original_translation)
def test_parent_language(self):
data = {
@@ -60,37 +64,54 @@ class TestTranslation(IntegrationTestCase):
source = "User"
self.assertNotEqual(_(source, lang="de"), _(source, lang="es"))
- def test_html_content_data_translation(self):
- # ruff: noqa: RUF001
+ def test_html_content_translation(self):
source = """
- MacBook Air lasts up to an incredible 12 hours between charges. So from your morning coffee to
- your evening commute, you can work unplugged. When it’s time to kick back and relax,
- you can get up to 12 hours of iTunes movie playback. And with up to 30 days of standby time,
- you can go away for weeks and pick up where you left off.Whatever the task,
- fifth-generation Intel Core i5 and i7 processors with Intel HD Graphics 6000 are up to it.
- """
-
+ To add dynamic subject, use jinja tags like
+
{{ doc.name }} Billed{{ doc.name }} Abgerechnet