intlify / nuxt3

Nuxt 3 Module for vue-i18n-next
MIT License
202 stars 19 forks source link

switchLocalePath #31

Open andrehrferreira opened 2 years ago

andrehrferreira commented 2 years ago

is it possible to use the switchLocalePath function?

kazu80 commented 2 years ago

I couldn't use SwitchLocalePath too. How to do switch locale ? Could you tell us example on Nuxt3 please

kazupon commented 2 years ago

I’m forcusing on nuxt/i18n. And currently, I’m developing core library for nuxt/i18n and it will be able to use as vue plugin library.

kazu80 commented 2 years ago

I wrote below code instead SwitchLocalePath

<script setup lang="ts">
import {useI18n} from "vue-i18n"
const i18n = useI18n()

const changeLocale = (locale: string) => {
  i18n.locale.value = locale
}
</script>

<template>
  <div class="lang-set">
    <ul>
      <li v-if="i18n.locale.value === 'ja'">
        <button class="lang-set-button__english" @click="changeLocale('en')">English</button>
      </li>
      <li v-else>
        <button class="lang-set-button__english" @click="changeLocale('ja')">日本語</button>
      </li>
    </ul>
  </div>
</template>