# i18n with Vue3、Vite ## npm ``` npm install --save vue-i18n@next ``` ## main.js ``` import { createI18n } from "vue-i18n"; import en from "./i18n/en.json"; import kr from "./i18n/kr.json"; const i18n = createI18n({ legacy: false, locale: "kr", globalInjection: true, messages: { en, kr, }, }); app.use(i18n); ``` ### globalInjection * Type: boolean * Default: undefined 是否全域使用,不需額外載入就能使用 $t 語系檔 ### legacy 要把 legacy 設為 false,才可以用 Composition API ## 使用 ### 變數 < template > ``` {{ $t('test') }} ``` ### 更換語系 < script setup > ``` import { useI18n } from 'vue-i18n' const { locale } = useI18n() ``` < template > ``` <select v-model="locale"> <option value="en">英文</option> <option value="kr">韓文</option> </select> ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up