Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to get reactivity on the translations in script on language change? #673

Closed
rbourtoutian opened this issue Aug 1, 2019 · 3 comments

Comments

@rbourtoutian
Copy link

I have a language selector :

<select @change="saveLocale($root.$i18n.locale)" v-model="$root.$i18n.locale">

and the saveLocale function :

saveLocale (locale) {
localStorage.setItem('locale', locale)
},

Upon changing the language, all $t(..) are changed in the template section, which is perfect. But I have an array of headers in the script section which is translated:

headers: [
{ text: this.$t('general.name', this.locale), value: 'name' },
{ text: this.$t('general.status'), value: 'approval_status'},
{ text: this.$t('general.created_dttm'), value: 'created_dttm'},
],

headers only gets translated on boot.load of the page, but when I change the language the headers translated texts don't translate.Only after page refresh the headers texts get translated as well.

Is there a way that I am missing to make the translated texts in the script part of vue component reactive as well???

@dzyubadmytro
Copy link

this one helped to me
#149 (comment)

@rbourtoutian
Copy link
Author

this one helped to me
#149 (comment)

Thanks for help, but I don't really figure out how to do this...There dont seem to be a clear example. Why is it this.$i18n.t and not this.$t as we usually do?

@rbourtoutian
Copy link
Author

PROBLEM SOLVED: the whole issue is not related to vue-i18n, it is related to the reactivity of the headers array I wanted to be re-translated upon language change.

To do so, you'll need to NOT send the array as an array in the "data()" portion, but return the headers array as a function in the 'methods()' portion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants