feat(scoped): support css selector scoped (#42)
* feat(scoped): support css selector scoped https://github.com/journey-ad/sd-webui-bilingual-localization/issues/41 * fix: avoid empty * .main
parent
cf54c4eb03
commit
e79b78402f
|
|
@ -116,7 +116,7 @@
|
|||
logger.log('Bilingual Localization initialized.')
|
||||
|
||||
// Load localization file
|
||||
const regex_scope = /^##(?<scope>\S+)##(?<skey>\S+)$/ // ##scope##.skey
|
||||
const regex_scope = /^##(?<scope>.+)##(?<skey>.+)$/ // ##scope##.skey
|
||||
i18n = JSON.parse(readFile(dirs[file]), (key, value) => {
|
||||
// parse regex translations
|
||||
if (key.startsWith('@@')) {
|
||||
|
|
@ -126,7 +126,18 @@
|
|||
}
|
||||
} else if (regex_scope.test(key)) {
|
||||
// parse scope translations
|
||||
const { scope, skey } = key.match(regex_scope).groups
|
||||
let { scope, skey } = key.match(regex_scope).groups
|
||||
|
||||
if (scope.startsWith('@')) {
|
||||
scope = scope.slice(1)
|
||||
} else {
|
||||
scope = '#' + scope
|
||||
}
|
||||
|
||||
if (!scope.length) {
|
||||
return value
|
||||
}
|
||||
|
||||
i18nScope[scope] ||= {}
|
||||
i18nScope[scope][skey] = value
|
||||
|
||||
|
|
@ -267,9 +278,9 @@
|
|||
scopes = scopedSource[source]
|
||||
|
||||
if (scopes) {
|
||||
console.log('scope', el, source);
|
||||
console.log('scope', el, source, scopes);
|
||||
for (let scope of scopes) {
|
||||
if (el.parentElement.closest(`#${scope}`)) {
|
||||
if (el.parentElement.closest(scope)) {
|
||||
translation = i18nScope[scope][source]
|
||||
break
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue