Loading...
Loading...
Use when writing or debugging code that imports vue-i18n (Vue 3 internationalization). Covers createI18n, useI18n, message syntax, i18n-t/i18n-n/i18n-d components, pluralization, datetime and number formatting, TypeScript schemas, lazy loading, bundle optimization, and v10/v11/v12 migration.
npx skill4agent add skilld-dev/vue-ecosystem-skills vue-i18n-skilldvue^3.0.0>= 22@nuxtjs/i18nlegacy: falsecreateI18nuseI18n()legacy: truev-tt()$t<i18n-t>tc$tct$ttc{name}%@intlify/unplugin-vue-i18nv-htmlescapeParameter: true// i18n.js
import { createI18n } from 'vue-i18n'
const i18n = createI18n({
legacy: false, // Composition API mode
locale: 'ja',
fallbackLocale: 'en',
messages: {
en: { message: { hello: 'hello world' } },
ja: { message: { hello: 'こんにちは、世界' } }
}
})
export default i18n// main.js
import { createApp } from 'vue'
import App from './App.vue'
import i18n from './i18n'
createApp(App).use(i18n).mount('#app')app.use(i18n)$t$d$n$rtglobalInjection: trueuseI18ni18n-ti18n-di18n-nglobalInstall: true<script setup>
import { useI18n } from 'vue-i18n'
const { t, locale } = useI18n()
</script>
<template>
<h1>{{ t('message.hello') }}</h1>
<p>{{ t('greeting', { name: 'Kyoko' }) }}</p>
<p>{{ $t('message.hello') }}</p><!-- works in templates via globalInjection -->
</template>useI18n()setupsetup'no apples | one apple | {count} apples't('apple', count, { count }) // or t('apple', { count }, choice)pluralRulesComposerpluralizationRulesconst { d, n } = useI18n()
d(new Date(), 'long') // named format from datetimeFormats option, else Intl fallback
n(1234567, 'currency') // named format from numberFormats option<i18n-t keypath="..." tag="p">locale.value = 'en'langAccept-Languageimport()setLocaleMessagemergeLocaleMessageDefineLocaleMessageDefineDateTimeFormatDefineNumberFormatuseI18nuseI18n({ messages: ... })useScope: 'global'$tglobalInjection: truelocalemissingmissingWarnfallbackWarn@:key{}@|vue-i18n/dist/*| Change | Version | Action |
|---|---|---|
| Legacy API mode deprecated | v11 | Move to |
| v11 | Replace with |
| v11 | Use |
| JIT message compilation default | v10 | Pre-compile for strict CSP |
| v10 | Use |
| v10 | Pass plural via options object |