From e4d527f0f226eb6809300e5b1b6c101b32709daf Mon Sep 17 00:00:00 2001 From: 134 Date: Mon, 13 Jul 2026 17:07:18 +0800 Subject: [PATCH] fix: translate HiCAD input and spaced copy --- vendor/zoo-modeling-app/localization.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/vendor/zoo-modeling-app/localization.ts b/vendor/zoo-modeling-app/localization.ts index d54993bfc..375d7497b 100644 --- a/vendor/zoo-modeling-app/localization.ts +++ b/vendor/zoo-modeling-app/localization.ts @@ -119,6 +119,17 @@ const excludedSelector = [ '.cm-content', '.cm-line', ].join(',') +const excludedAttributeSelector = [ + 'script', + 'style', + '.cm-editor', + '.cm-content', + '.cm-line', +].join(',') + +function normalizeLookupKey(value: string) { + return value.replace(/\s+/g, ' ').trim() +} function isExcluded(node: Node) { const element = @@ -131,7 +142,7 @@ function isExcluded(node: Node) { function translateTextNode(node: Text) { if (isExcluded(node)) return const value = node.nodeValue || '' - const normalized = value.trim() + const normalized = normalizeLookupKey(value) const translated = translations.get(normalized) if (!translated || translated === normalized) return @@ -141,9 +152,9 @@ function translateTextNode(node: Text) { } function translateElement(element: Element) { - if (isExcluded(element)) return + if (element.closest(excludedAttributeSelector)) return for (const attribute of translatableAttributes) { - const value = element.getAttribute(attribute)?.trim() + const value = normalizeLookupKey(element.getAttribute(attribute) || '') if (!value) continue const translated = translations.get(value) if (translated) element.setAttribute(attribute, translated)