Skip to content

Namespaces

Split the catalogs and load the messages each route needs.

common and additional catalogs

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

export default defineMeekoConfig({
  modules: ['@meekojs/i18n'],
  i18n: {
    defaultLocale: 'es',
    catalogs: {
      es: {
        common: 'app/locales/es/common.json',
        checkout: 'app/locales/es/checkout.json',
      },
      en: {
        common: 'app/locales/en/common.json',
        checkout: 'app/locales/en/checkout.json',
      },
    },
    routes: { '/checkout': ['checkout'] },
  },
})

common is always loaded, together with the namespaces of global, such as the catalog of a shared shell. routes maps exact IDs of the manifest to additional namespaces. Every language declares the same namespaces.

A real namespace on this page

This route loads the checkout namespace through the site's routes option. The following result comes from that catalog:

Confirm order

Your order has 3 products.

app/locales/es/checkout.json json
{
  "checkout": {
    "title": "Confirmar pedido",
    "summary": "Tu pedido tiene {total} productos."
  }
}

Organizing the keys

The name of the namespace organizes loading; it does not add a prefix to the keys. Here checkout.title comes from the checkout object of the JSON. Keys of different namespaces must be unique.

The generated types include the keys of every namespace. Use each message on a route that loads its catalog: a key that TypeScript knows also needs to be available at runtime.

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