Lang Switcher

When nuxt-i18n loads in your app, it adds your locales configuration to this.$i18n (or app.i18n), which makes it really easy to display a lang switcher anywhere in your app.

Here's an example lang switcher where a name key has been added to each locale object in order to display friendlier titles for each link:

  v-for="locale in availableLocales"
  :to="switchLocalePath(locale.code)">{{ }}</nuxt-link>
computed: {
  availableLocales () {
    return this.$i18n.locales.filter(i => i.code !== this.$i18n.locale)
['nuxt-i18n', {
  locales: [
      code: 'en',
      name: 'English'
      code: 'es',
      name: 'Español'
      code: 'fr',
      name: 'Français'

When using detectBrowserLanguage and wanting to persist locale on a route change, you must call one of the functions that update the stored locale cookie. Call either setLocaleCookie(locale) to persist just the cookie locale or setLocale(locale) to both persist the cookie locale and switch the route to the specified locale. Otherwise, locale might switch back to the saved one during navigation.

The template code might look like this, for example:

  v-for="locale in availableLocales"
  @click.prevent.stop="setLocale(locale.code)">{{ }}</a>

Dynamic route parameters

Dealing with dynamic route parameters requires a bit more work because you need to provide parameters translations to nuxt-i18n. For this purpose, nuxt-i18n's store module exposes a routeParams state property that will be merged with route params when generating lang switch routes with switchLocalePath().

Make sure that Vuex is enabled in your app and that you did not set vuex option to false in nuxt-i18n's options.

To provide dynamic parameters translations, dispatch the i18n/setRouteParams mutation as early as possible when loading a page. The passed in object must contain the mappings from the locale code to an object with a mapping from slug name to expected slug value for given locale.

An example:

  <!-- pages/post/_postId.vue -->

export default {
  async asyncData ({ store }) {
    await store.dispatch('i18n/setRouteParams', {
      en: { postId: 'my-post' },
      fr: { postId: 'mon-article' }
    return {
      // your data

nuxt-i18n won't reset parameters translations for you, this means that if you use identical parameters for different routes, navigating between those routes might result in conflicting parameters. Make sure you always set params translations in such cases.