Skip to content

Commit

Permalink
fix: vue $t update every time language or translation has changed (#3348
Browse files Browse the repository at this point in the history
)
  • Loading branch information
stepan662 authored Jun 20, 2024
1 parent ff331be commit c1ea134
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions packages/vue/src/VueTolgee.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { App } from 'vue';
import { ref } from 'vue';
import {
getTranslateProps,
TolgeeInstance,
Expand All @@ -19,23 +20,23 @@ export const VueTolgee = {
throw new Error('Tolgee instance not passed in options');
}

app.mixin({
beforeCreate() {
this.$options.__keySubscription = tolgee.onNsUpdate(() => {
this.$forceUpdate();
});
},
unmounted() {
this.$options.__keySubscription.unsubscribe();
},
methods: {
const createTFunc = () => {
return (...props) => {
// @ts-ignore
$t(...props) {
// @ts-ignore
const params = getTranslateProps(...props);
const { ns } = params;
this.$options.__keySubscription.subscribeNs(ns);
return tolgee.t(params);
const params = getTranslateProps(...props);
return tolgee.t(params);
};
};

const tFunc = ref(createTFunc());
tolgee.on('update', () => {
tFunc.value = createTFunc();
});

app.mixin({
computed: {
$t() {
return tFunc.value;
},
},
});
Expand Down

0 comments on commit c1ea134

Please sign in to comment.