Skip to content

Commit

Permalink
Fix setting language via API
Browse files Browse the repository at this point in the history
When using `setLanguage`, the new language was only applied after the next render update due to missing reactivity.
  • Loading branch information
t11r committed Jan 6, 2025
1 parent dcab8db commit 06124c0
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/plugins/i18n.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { ref } from 'vue';

export default {
install: (app) => {
let translation = null;
const translation = ref(null);

// eslint-disable-next-line no-param-reassign
app.config.globalProperties.$translate = (string, fallback) => {
if (translation && translation[string]) {
return translation[string];
if (translation.value?.[string]) {
return translation.value[string];
}

if (import.meta.env.DEV && translation) {
if (import.meta.env.DEV && translation.value) {
// eslint-disable-next-line no-console
console.warn(`Missing translation for "${string}"`);
}
Expand All @@ -21,7 +23,7 @@ export default {
// value is the translated string, e.g. { key: 'Schlüssel' }
// eslint-disable-next-line no-param-reassign
app.config.globalProperties.$translate.setTranslation = (translationObject) => {
translation = translationObject;
translation.value = translationObject;
};
},
};

0 comments on commit 06124c0

Please sign in to comment.