Skip to content

Commit 9bbdede

Browse files
committed
Fix setting language via API
When using `setLanguage`, the new language was only applied after the next render update due to missing reactivity.
1 parent cb5371e commit 9bbdede

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/plugins/i18n.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
import { ref } from 'vue';
2+
13
export default {
24
install: (app) => {
3-
let translation = null;
5+
const translation = ref(null);
46

57
// eslint-disable-next-line no-param-reassign
68
app.config.globalProperties.$translate = (string, fallback) => {
7-
if (translation && translation[string]) {
8-
return translation[string];
9+
if (translation.value?.[string]) {
10+
return translation.value[string];
911
}
1012

1113
if (import.meta.env.DEV && translation) {
@@ -21,7 +23,7 @@ export default {
2123
// value is the translated string, e.g. { key: 'Schlüssel' }
2224
// eslint-disable-next-line no-param-reassign
2325
app.config.globalProperties.$translate.setTranslation = (translationObject) => {
24-
translation = translationObject;
26+
translation.value = translationObject;
2527
};
2628
},
2729
};

0 commit comments

Comments
 (0)