Monorepos

One root config with projects, each project with its own locales and its own config.

A monorepo can hold several projects, for example a web app and a UI library, each with its own locale files. List them in the root config with projects:

x18n.config.ts
import { defineConfig } from '@x18n/core'

export default defineConfig({
  sourceLocale: 'en',
  projects: ['apps/*', 'packages/ui'],
})

Each entry of projects is a glob of directories, relative to the root config. Each matching directory is one project.

Project configs

A project directory can have its own x18n.config.*. The project inherits the options of the root config, and its own config overrides them. The rules are the same as for one project: see How x18n merges the config.

apps/web/x18n.config.ts
import { defineConfig } from '@x18n/core'

export default defineConfig({
  resources: [{ pattern: 'locales/{locale}.json' }],
  checks: {
    'unused-key': 'error',
  },
})

Paths in a project config are relative to the project directory. A project directory without a config file is a project with the root options and its own detection.

Plugins of the root config and of the project config both apply. Presets of the project config replace the presets of the root config.

Project names

The name of a project is its path from the root, such as apps/web, unless its config sets name. x18n status lists the names.

Commands

Read commands work on every project:

  • x18n check checks every project, and reports them together.
  • x18n status, x18n keys and x18n usages show every project.
  • The UI and the editor show every project.

Pass --project <name> to work on one project. Commands that write files (set, apply, rename, delete, fill, format, extract) and x18n prompt need one project. Without --project, they stop with X18N0003.

x18n check --project apps/web
x18n set nav.home --value "Home" --project apps/web

Run the commands from the root of the monorepo. The CLI uses the first config file that it finds from the current directory upward. If you run it in apps/web, it finds apps/web/x18n.config.ts first and loads that project alone, without the root options.