fix: translate HiCAD input and spaced copy
This commit is contained in:
parent
bb62fa680f
commit
e4d527f0f2
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-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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user