Petite Vue I18n

11.3.2 · active · verified Sun Apr 19

petite-vue-i18n is a specialized, lightweight internationalization library for Vue 3 applications, offering a trimmed-down feature set compared to the full vue-i18n package. Currently at version 11.3.2, it maintains a regular release cadence with frequent bug fixes and minor improvements, often in sync with the main vue-i18n project. Its primary differentiation lies in its significantly smaller bundle size (up to 45% smaller for runtime-only builds) by exclusively supporting the Composition API and focusing solely on core translation capabilities. It omits features like date/number formatting ($n, $d), rich text rendering ($rt), hierarchical message handling out-of-the-box, the v-t directive, and components like i18n-t, making it ideal for projects where only basic text translation is required and bundle size is critical. Migration to the full vue-i18n is designed to be seamless if more features become necessary later.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to set up `petite-vue-i18n` with `createI18n`, use the `useI18n` hook for translations (`t`), and dynamically switch locales in a Vue 3 application.

import { createApp } from 'vue'
import { createI18n, useI18n } from 'petite-vue-i18n'

const messages = {
  en: {
    'hello world': 'Hello world from petite-vue-i18n!',
    'greeting': 'Welcome, {name}!',
    'about': 'This is a lightweight i18n solution.'
  },
  fr: {
    'hello world': 'Bonjour le monde de petite-vue-i18n !',
    'greeting': 'Bienvenue, {name} !',
    'about': 'Ceci est une solution i18n légère.'
  }
}

const i18n = createI18n({
  locale: 'en',
  fallbackLocale: 'fr',
  messages
})

const app = createApp({
  setup() {
    const { t, locale } = useI18n()
    return { t, locale }
  },
  template: `
    <div id="app">
      <h1>{{ t('hello world') }}</h1>
      <p>{{ t('greeting', { name: 'User' }) }}</p>
      <p>{{ t('about') }}</p>
      <button @click="locale = 'fr'">Switch to French</button>
      <button @click="locale = 'en'">Switch to English</button>
    </div>
  `
})

app.use(i18n)
app.mount('#app')

view raw JSON →