Skip to content

Commit 26dbd3c

Browse files
committed
feat: data-t attribute for translation raw inside html templates
1 parent f0c00c4 commit 26dbd3c

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/ui/index.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@ export function createWidget(container: Element | string,
2323
widget.config.globalProperties.$i18n = inject.i18n
2424
widget.config.globalProperties.settings = settings
2525

26-
watch(translator.localeRef, (locale) => {
27-
if (locale) {
28-
translator.locale = locale
29-
}
30-
})
31-
3226
installComponents(widget)
3327

3428
container = typeof container === 'string' ? document.querySelector(container)! : container
@@ -41,5 +35,16 @@ export function createWidget(container: Element | string,
4135
widget.provide('templates', templates)
4236
widget.mount(container)
4337

38+
watch(translator.localeRef, (locale) => {
39+
if(locale !== translator.locale ){
40+
translator.locale = locale
41+
}
42+
if (locale) {
43+
document.querySelectorAll('[data-t]').forEach((el) => {
44+
el.textContent = translator.t((el as HTMLElement).dataset.t)
45+
});
46+
}
47+
}, { immediate: true, flush: 'post' })
48+
4449
return widget;
4550
}

0 commit comments

Comments
 (0)