# i18n

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

:hero-figure{name="i18n"}

```vue [src/App.vue]
<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>
```

```ts [server/api/greeting.ts]
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' }),
  }
})
```

```json [locales/es/segments/52/5220fa743183ff60.json]
{
  "hash": "5220fa743183ff60",
  "source": "Deploy your agent",
  "text": "Despliega tu agente",
  "origin": "human",
  "review": "edited",
  "derived": "fresh",
  "updatedAt": "2026-11-07T12:00:00.000Z"
}
```

### [No keys](https://vitehub.dev/docs/i18n/configure#write-messages)

Write ``t`Save` `` in the source language. `t` and `<Trans>` work in templates with no import.

### [One locale for each request](https://vitehub.dev/docs/i18n/server-api#how-the-server-picks-the-locale)

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

### [IDs in production, not text](https://vitehub.dev/docs/i18n/configure#what-the-build-does)

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](https://vitehub.dev/docs/i18n/configure#translate-the-messages)

`locales/` is a [Diglot](https://github.com/danielroe/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](https://vitehub.dev/docs/i18n/get-started)

A Vue page and a server route in English and Spanish, with no provider account.

### [Know the limits](https://vitehub.dev/docs/i18n/limits-and-errors#limits)

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

Use i18n to translate the text of a Vue app and its server routes. Do not add message keys, and do not add a config file for another i18n library. Write each message in the source language, which is the first entry of `i18n.locales`.

In Vue templates, use ``{{ t`Text` }}`` and `<Trans>` with no import. In scripts and server code, import `t`, `plural`, `select`, `selectOrdinal`, and `msg` from `vite-hub/i18n`. Do not call `t` at the top level of a module. Use `msg` there, and call `translate()` where the code runs.

Check coverage with `pnpm vitehub i18n status --json`. Each translation is a Diglot record in `locales/<locale>/segments/<hh>/<hash>.json`: edit its `text` field only, or use `pnpm vitehub i18n import <locale> <file.po>`. A translation must keep each `{0}` of its message. i18n needs Nitro 3. Use Vite with Nitro 3, or Nuxt 5.

<!-- vitehub-docs:section-links -->
## In this section

- [Overview](https://vitehub.dev/raw/docs/i18n.md) (this page)
- [Get started](https://vitehub.dev/raw/docs/i18n/get-started.md)
- [Configure](https://vitehub.dev/raw/docs/i18n/configure.md)
- [Server API](https://vitehub.dev/raw/docs/i18n/server-api.md)
- [Agent capability](https://vitehub.dev/raw/docs/i18n/agent-capability.md)
- [Limits and errors](https://vitehub.dev/raw/docs/i18n/limits-and-errors.md)

Next: [I18N_INVALID_TRANSLATION](https://vitehub.dev/raw/docs/i18n/diagnostics/i18n_invalid_translation.md)

All pages: [llms.txt](https://vitehub.dev/llms.txt)
