πŸ“š Reference


πŸ“œ Chapter


Troubleshooting

@intlify/unplugin-vue-i18n

i18n, l10n, i18next

react-i18next

next-intl

i18next-fs-backend

β€£

Vue I18n


μ„€μΉ˜

# npm
npm install vue-i18n@11

# yarn
yarn add vue-i18n@11

# pnpm
pnpm add vue-i18n@11

μ„€μ •: main.js λ˜λŠ” main.ts

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>
import { useI18n } from 'vue-i18n'

const { t } = useI18n()

console.log(t('message.hello')) // 'μ•ˆλ…•ν•˜μ„Έμš”, 세상!'
</script>

<template>
  <h1>{{ t('message.hello') }}</h1>
</template>