vue-i18n 플러그인은 언어세팅을 위한 라이브러리로 서비스 내 다국어 기능이 필요하거나, 서버 데이터를 사용자 환경에 맞게 번역이 필요할 때 활용된다.
npm install vue-i18n@8 or yarn add vue-i18n@8
//Vue Cli 3.x 이상 버전
vue add i18n
// locales/index.js
const messages = {
ko: {
field: {
receiving: '입고',
shipping: '출고',
stock: '재고',
mdm: '기준정보',
},
},
}
export default messages
import { createApp } from 'vue'
import App from './App.vue'
import { createI18n } from 'vue-i18n'
import messages from './locales'
const i18 = new createI18n({
legacy: false, // set 'false' to use Composition API
locale: 'ko',
messages,
})
const app = createApp(App)
app.use(i18)
app.provide(i18, '$t')
app.mount('#app')
Schema : messages, datetimeFormats, numberFormats 등 i18n의 리소스 Locales : 다국어 데이터의 기본 언어 Legacy : 레거시 모드의 on/off (i18n이 제공하는 내장 API 사용 유무)
<template>
<div class="flex flex-col justify-between w-150 bg-gray-800 h-full">
<div class="lnb-wrap">
<ul v-for="(title, index) in state.lnb" :key="index">
<li class="p-10">
<div class="text-xl text-gray-100" @click="clickTitle(title)">
{{ $t(`field.${title[0]}`) }}
</div>
<div v-for="{ label, route } in title[1].child" :key="route">
<div
v-if="title[1].isActive"
class="text-gray-100"
@click="goPage(route, label)"
>
{{ $t(`field.${label}`) }}
</div>
</div>
</li>
</ul>
</div>
<div>
<p>{{ state.id }}</p>
<button @click="logout">로그아웃</button>
</div>
</div>
</template>
참조