fix: translate HiCAD input and spaced copy
This commit is contained in:
parent
f29433a91b
commit
00cbfce56d
17
vendor/zoo-modeling-app/localization.ts
vendored
17
vendor/zoo-modeling-app/localization.ts
vendored
@ -119,6 +119,17 @@ const excludedSelector = [
|
|||||||
'.cm-content',
|
'.cm-content',
|
||||||
'.cm-line',
|
'.cm-line',
|
||||||
].join(',')
|
].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) {
|
function isExcluded(node: Node) {
|
||||||
const element =
|
const element =
|
||||||
@ -131,7 +142,7 @@ function isExcluded(node: Node) {
|
|||||||
function translateTextNode(node: Text) {
|
function translateTextNode(node: Text) {
|
||||||
if (isExcluded(node)) return
|
if (isExcluded(node)) return
|
||||||
const value = node.nodeValue || ''
|
const value = node.nodeValue || ''
|
||||||
const normalized = value.trim()
|
const normalized = normalizeLookupKey(value)
|
||||||
const translated = translations.get(normalized)
|
const translated = translations.get(normalized)
|
||||||
if (!translated || translated === normalized) return
|
if (!translated || translated === normalized) return
|
||||||
|
|
||||||
@ -141,9 +152,9 @@ function translateTextNode(node: Text) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function translateElement(element: Element) {
|
function translateElement(element: Element) {
|
||||||
if (isExcluded(element)) return
|
if (element.closest(excludedAttributeSelector)) return
|
||||||
for (const attribute of translatableAttributes) {
|
for (const attribute of translatableAttributes) {
|
||||||
const value = element.getAttribute(attribute)?.trim()
|
const value = normalizeLookupKey(element.getAttribute(attribute) || '')
|
||||||
if (!value) continue
|
if (!value) continue
|
||||||
const translated = translations.get(value)
|
const translated = translations.get(value)
|
||||||
if (translated) element.setAttribute(attribute, translated)
|
if (translated) element.setAttribute(attribute, translated)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user