Skip to content
Snippets Groups Projects
LocaleChanger.vue 666 B
Newer Older
Florent Lavelle's avatar
Florent Lavelle committed
<template>
  <div id="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: 'LocaleChanger',

  data () {
    return {
      langs: ['fr', 'en'],
    }
  },

  watch: {
    '$i18n.locale': function(newValue, oldValue) {
      if (newValue !== oldValue) {
        const to = this.$router.resolve({
          params: { locale: newValue },
          query: this.$route.query
        });
Florent Lavelle's avatar
Florent Lavelle committed
        this.$router.push(to.location);
      }
    }
  }

}
</script>