@parlajs/x18n-plugin
Toolingpnpm add -D @x18n/cli @parlajs/x18n-plugin, a plugin for
x18n.
import parla from '@parlajs/x18n-plugin';import { defineConfig } from '@x18n/cli';
export default defineConfig({ sourceLocale: 'en', locales: ['en', 'it'], // Parla's configs name every catalog; by default x18n also takes every `locales/**`. resources: [], // `checkout:cart.items`: Parla's namespaces and keys may contain dots. namespace: { separator: ':' }, plugins: [parla()], usage: { include: ['src/**/*.{ts,tsx}'], exclude: ['src/parla/**'] },});Keep src/parla/ in .gitignore: x18n would read its generated chunks as catalogs.
What it reads
Section titled “What it reads”| Catalogs | Each under the namespace its parla.config.ts gives it |
| Usages | t.ns.key() on a t from useParla([ns]), useParlaLoaded([ns]), await parla.load([ns]), parla.loaded([ns]) or a parameter t or { t } typed Translations<typeof ns> |
| Templates | .vue, .svelte and .astro: scripts, frontmatter and template expressions |
| Params and markup | Parla’s own ICU and MF2 parsers, with the config’s functions and markup |
| Custom formats | A namespace’s messages through its own adapter, from the config’s formats |
| Selects | Branches that need different params are left to TypeScript, which checks each one |
A key chosen at run time, t.ns.group[key](), or a group or namespace passed on, pick(t.ns.group),
counts every key under it as used. x18n reads no types, so annotate a callback’s t:
(t: Translations<typeof ns>) => t.ns.key().
For templates, add their extensions to usage.include. A namespace counts only when imported from
its namespaces/{ns}.js. A catalog read through parseFile
needs an x18n format for its extension too, since x18n also writes it.
Options
Section titled “Options”| Option | Default | |
|---|---|---|
callees |
['useParla', 'useParlaLoaded'] |
Hooks that take a list of namespaces and return { t } |
configs |
every **/parla.config.ts |
Configs to read, relative to x18n’s root |
The plugin imports, and so runs, every config it reads: set configs where others may add files.