1

I want to translate my app English to German. on the language change event, I wrote this code

changeLocale (locale) {
      i18n.locale = locale.language
      VueCookies.set('UserLanguage', locale.language)
      // window.location.reload() this one is reloading page 
      this.$root.reload() // this one is not working 
    },

and I want to translate this data in vuejs file :

 DashboardData: [{'name': this.$t('IVR')}, {'name': this.$t('DTML')}, {'name': this.$t('SSH')}]

if I do window.location.reload(), it's working perfectly but I don't want to reload the page so, I am thinking to reload root in vue, I am not sure about this.

Is there any way to reload the root element or all property of the whole app?

JYOTI SAPARIYA
  • 384
  • 2
  • 13
  • I think that `this.$t` is undefined if you try to use it in the `data` block. You could try using `this.$i18n.t` instead, or moving your `DashboardData` to a computed property and keep using `this.$t`. – Ricky Ruiz Mar 26 '19 at 17:42

2 Answers2

0

If you are just trying to perform a safe reload via vue.js , there is a simple method you can use ...

vm.$forceUpdate();

for further info you can go here

adib
  • 347
  • 3
  • 5
0

Why reload ? I am using vue-i18n and i don't reload my page. Here's the code:

home.vue

<v-list-tile @click="locale='fr'">
...
watch:{
   locale(val) {
       this.$i18n.locale=val;
    } 
},
mounted: function() {
   this.locale = this.$i18n.locale;
},

my app.js

...
import VueI18n from 'vue-i18n';
import messages from './lang/messages'
import dateTimeFormats from './lang/dateTimeFormats'
import numberFormats from './lang/numberFormats'
...
Vue.use(VueI18n);
let locale = navigator.language;
const i18n = new VueI18n({
  fallbackLocale: 'gb',
  locale: locale,
  messages,
  dateTimeFormats,
  numberFormats
})
...
const app = new Vue({
    el: '#app',
    router,
    store,
    i18n,
    components:{
        App
    }
});
Charles G
  • 1,151
  • 10
  • 9