Skip to content

Commit 4bf1fea

Browse files
committed
refactor: improve translation handling for content widgets
Signed-off-by: Samuel Amen Ague <ague.samuel27@gmail.com>
1 parent 4aaca24 commit 4bf1fea

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

pycompiler_ark/Ui/i18n.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,10 @@ def _binding_for_name(name: str) -> str:
623623
key = name[len(prefix) :]
624624
if key in tr:
625625
return key
626-
return name
626+
# Do not fall back to the object name: content widgets like QTextEdit
627+
# named "log" have setText() but no text(), so translate() would write
628+
# the name into the widget permanently.
629+
return ""
627630

628631
def _tooltip_for_name(name: str) -> str:
629632
if not name:
@@ -670,7 +673,14 @@ def _iter_objects(root: Any):
670673
for child in reversed(children):
671674
stack.append(child)
672675

676+
def _is_content_edit(obj: Any) -> bool:
677+
"""True for multiline editors that must not receive i18n setText()."""
678+
cls_name = type(obj).__name__
679+
return cls_name in ("QTextEdit", "QPlainTextEdit")
680+
673681
def _apply_text(obj: Any, key: str, default: str | None = None) -> None:
682+
if _is_content_edit(obj):
683+
return
674684
if hasattr(obj, "setText"):
675685
value = translate(self.id, key, default)
676686
if isinstance(value, str) and value:
@@ -703,7 +713,7 @@ def _apply_tab_text(obj: Any, key: str, default: str | None = None) -> None:
703713
for obj in _iter_objects(self):
704714
name = _object_name(obj)
705715
text_key = _prop(obj, "i18n_text_key") or _binding_for_name(name)
706-
if text_key:
716+
if text_key and not _is_content_edit(obj):
707717
system_key = _prop(obj, "i18n_text_system_key")
708718
system_attr = _prop(obj, "i18n_system_attr")
709719
format_attr = _prop(obj, "i18n_format_attr")

0 commit comments

Comments
 (0)