0 votes
in VueJS by
How do you perform locale changing?

1 Answer

0 votes
by

All child components of a root instance are localized using the locale property of the VueI18n class. You can change the value of the locale property of the VueI18n instance as below.

const i18n = new VueI18n({
  locale: 'de', // set locale
  ...
})

// create root Vue instance
new Vue({
  i18n,
  ...
}).$mount('#app')

// change other locale
i18n.locale = 'en'

You can also use component's VueI18n instance referenced as the $i18n property which will be used to change the locale.

<template>
  <div class="locale-changer">
    <select v-model="$i18n.locale">
      <option v-for="(lang, i) in langs" :key="`Lang${i}`" :value="lang">{{ lang }}</option>
    </select>
  </div>
</template>

<script>
export default {
  name: 'locale-changer',
  data () {
    return { langs: ['de', 'en'] }
  }
}
</script>

Related questions

0 votes
asked Sep 14, 2023 in VueJS by AdilsonLima
0 votes
asked Sep 12, 2023 in VueJS by AdilsonLima
...