Skip to content

Installation

Register the module, add your catalogs and use your first translation.

Before you start

You need a Meeko application, Node.js 24 or later and Meeko >=1.8 <2. The i18n module ships separately; you can use it with your application's components.

Terminal sh
pnpm add @meekojs/i18n

Configure the module

meeko.config.ts ts
import { defineMeekoConfig } from '@meekojs/meeko/framework'

export default defineMeekoConfig({
  site: 'https://example.com',
  modules: ['@meekojs/i18n'],
  i18n: {
    defaultLocale: 'es',
    catalogs: {
      es: 'app/locales/es.json',
      en: 'app/locales/en.json',
    },
  },
})

Catalog paths are relative to the project root and must stay inside it. defaultLocale must name one of the configured languages.

Create the catalogs

app/locales/es.json json
{
  "greeting": "Hola {name}",
  "ready": "Listo para traducir",
  "cart": {
    "items": {
      "plural": "total",
      "forms": {
        "=0": "Tu cesta está vacía",
        "one": "{count} elemento en tu cesta",
        "other": "{count} elementos en tu cesta"
      }
    }
  }
}
app/locales/en.json json
{
  "greeting": "Hello {name}",
  "ready": "Ready to translate",
  "cart": {
    "items": {
      "plural": "total",
      "forms": {
        "=0": "Your cart is empty",
        "one": "{count} item in your cart",
        "other": "{count} items in your cart"
      }
    }
  }
}

Both languages declare the same keys and parameters. The structure of cart produces the key cart.items.

Translate in a component

meeko
<script lang="ts">
  const { t } = useI18n()
  const name = signal('Meeko')
</script>

<template>
  <p>{t('greeting', { name: name.value })}</p>
  <p>{t('cart.items', { total: 3 })}</p>
</template>

useI18n is auto-imported in components once the module is registered. It also supports an explicit import from @meekojs/i18n. The plugin provides one instance per application and SSR request.

After changing the catalogs, run meeko check to verify the generated contract. Do not edit the types in .meeko by hand.

Continue with messages and parameters or try the playground.

Was this page helpful?

Add a comment

It is sent when you choose “Yes” or “No”. Only the page, your answer and the comment are stored: no cookies and no personal data.

0 of 2000 characters