GitHub 37
Skip to content
ViteHub is still experimental. Expect bugs and breaking changes.

i18n

Write the app in your language. No keys. Translators edit one file per locale, and each request gets its own locale.

<script setup lang="ts">
import { useLocale } from 'vite-hub/i18n/vue'

const { locale, setLocale } = useLocale()
</script>

<template>
  <!-- No import and no key: write the English text -->
  <h1>{{ t`Deploy your agent` }}</h1>
  <p><Trans>Read the <a href="/docs">docs</a> first.</Trans></p>
  <button @click="setLocale(locale === 'en' ? 'es' : 'en')">{{ locale }}</button>
</template>
src/App.vue
import { defineEventHandler, getQuery } from 'h3'
import { getLocale, plural, t } from 'vite-hub/i18n'

// No event to pass: `t` reads the locale of this request.
export default defineEventHandler((event) => {
  const count = Number(getQuery(event).count ?? 1)
  return {
    locale: getLocale(),
    message: t`Payment received`,
    items: plural(count, { one: '# item', other: '# items' }),
  }
})
server/api/greeting.ts
{
  "hash": "5220fa743183ff60",
  "source": "Deploy your agent",
  "text": "Despliega tu agente",
  "origin": "human",
  "review": "edited",
  "derived": "fresh",
  "updatedAt": "2026-11-07T12:00:00.000Z"
}
locales/es/segments/52/5220fa743183ff60.json

No keys

Write t`Save` in your source language. t and <Trans> work in Vue templates without imports.

One locale for each request

The locale cookie, then Accept-Language, then the source locale. Server code needs no event.

IDs in production, not text

The build compiles each message to a short ID and collects the source text. Each locale is a separate chunk that loads when the page needs it.

One file for each translation

locales/ is a Diglot translations folder with one record for each message. vitehub i18n status shows what is missing, and PO files go in and out.

Translate an app in one tutorial

Translate a Vue page and an API route from English to Spanish with no provider account.

Know the limits

Nitro 3 only: Vite with Nitro 3, Nuxt 4.7 with the nitro package, or Nuxt 5. Each error code has a fix.