when using vue-i18n, force langauge in typescript

To force language when using vue-i18n in Typescript, you need to create a new instance of VueI18n while providing the language you want to force as follows:

index.ts
import Vue from 'vue';
import VueI18n from 'vue-i18n';

// Import translation messages
import messages from '@/i18n';

// Create new instance of VueI18n using the language you want to force.
const i18n = new VueI18n({
  // fallback language
  fallbackLocale: 'en',
  // language you want to force
  locale: 'fr',
  messages,
});

new Vue({
  i18n,
  // ... rest of your Vue app
}).$mount('#app');
397 chars
20 lines

This will instantiate the VueI18n instance with the language fr and provide it to your Vue application's options via the i18n property.

related categories

gistlibby LogSnag