DanteC
DanteC

Reputation: 378

Vue i18n - How do I get the current locale inside the i18n component options?

I'm trying to expand the already loaded localizations for a specific component and I would like to do something like this:

export default {
  name: 'General',
  components: {
    Header,
    Content,
    NextPageButton
  },
  i18n: {
    messages: {
      [this.$i18n.locale]: { message: require('@/locales/' + this.$i18n.locale + '/tso/general.json') }
    }
  }

Problem is of course that the $i18n is undefined inside the i18n options. How can I retrieve the current locale here?

Upvotes: 2

Views: 4909

Answers (1)

Flink
Flink

Reputation: 1006

I use the Vue instance like: this.Vue.$i18n.locale

Another way of access is this.$root.$i18n.locale

Upvotes: 2

Related Questions