Opinionated Internationalization (i18n) Vue plugin.
Lazy loading of locales
Fallbacking
Message Format features
Standard & nested keys
t('foo') resolves foot('foo.bar') resolves foo ➡️ bart('foo.bar.baz') resolves foo ➡️ bar ➡️ bazNamed interpolation
Hello {name} + t('key', { name: 'John' }) = Hello JohnList interpolation
Hello {0} {1} + t('key', ['John', 'Doe']) = Hello John DoePluralization
car | cars + t('key', 0) = carscar | cars + t('key', 1) = carcar | cars + t('key', 2) = carsno apples | one apple | {count} apples + t('key', 0) = no applesno apples | one apple | {count} apples + t('key', 1) = one appleno apples | one apple | {count} apples + t('key', 2) = 2 applesSupports Server-Side Rendering (SSR) & Static Site Generation (SSG)
This package is mainly meant to be used with Vite SSG.
The createI18n function returns a Promise that resolves to the i18n plugin, so you must asynchronously use it in your app.
This is required to ensure the following behaviors:
import { createI18n } from '@kevinmarrec/vue-i18n'
import { ViteSSG } from 'vite-ssg/single-page'
import App from './App.vue'
export const createApp = ViteSSG(App, ({ app }) => {
const i18n = await createI18n({
messages: import.meta.glob('./locales/*.{json,yaml,yml}')
})
app.use(i18n)
})
<script setup lang="ts">
import { useI18n } from '@kevinmarrec/vue-i18n'
const { t } = useI18n()
</script>
<template>
<div>{{ t('welcome') }}</div>
</template>
We use cookies
We use cookies to analyze traffic and improve your experience. You can accept or reject analytics cookies.