π Reference
π Chapter
β£
# npm
npm install vue-i18n@11
# yarn
yarn add vue-i18n@11
# pnpm
pnpm add vue-i18n@11
import { createApp } from 'vue'
import App from './App.vue'
import { createI18n } from 'vue-i18n'
// μΈμ΄λ³ λ©μμ§ μ μ
const messages = {
en: {
message: {
hello: 'Hello, world!'
}
},
ko: {
message: {
hello: 'μλ
νμΈμ, μΈμ!'
}
}
}
const i18n = createI18n({
locale: 'ko', // κΈ°λ³Έ μΈμ΄ μ€μ
fallbackLocale: 'en', // κΈ°λ³Έ μΈμ΄κ° μμ λ λ체 μΈμ΄
messages,
})
const app = createApp(App)
app.use(i18n)
app.mount('#app')
<script setup>
ꡬ문μμ useI18n
ν
μ μ¬μ©νκ±°λ, this.$t
λ₯Ό μ΄μ©ν΄ λ²μ λ©μμ§λ₯Ό κ°μ Έμ¬ μ μλ€.<script setup>
import { useI18n } from 'vue-i18n'
const { t } = useI18n()
console.log(t('message.hello')) // 'μλ
νμΈμ, μΈμ!'
</script>
<template>
<h1>{{ t('message.hello') }}</h1>
</template>