show an example of locale: 'fr', vue-i18n in javascript

To set locale to 'fr', you need to modify the locale value in VueI18n instance, like this:

index.tsx
import Vue from 'vue';
import VueI18n from 'vue-i18n';
import messages from './messages.js';

Vue.use(VueI18n);

const i18n = new VueI18n({
  locale: 'fr', // set locale to French (fr)
  messages, // set locale messages
});

new Vue({
  i18n,
}).$mount('#app');
262 chars
15 lines

Here, the locale of the i18n object has been set to 'fr'.

For this to work you need to have imported the vue-i18n module and the messages object with the French translations.

Note: if fr translations are not available in the messages.js, an error will occur.

related categories

gistlibby LogSnag