Skip to content

CLI and Vite plugin

Core

pnpm add -D @parlajs/compiler. Builds catalogs into typed namespaces; ICU and MF2 are built in.

parla build [--watch] catalog.js, namespaces/, messages/
parla check [--json] validate; exit 1 on errors
[--strict] warnings fail too
Option Commands Default
-c, --config <file> both parla.config.ts
-w, --watch build Rebuilds on catalog or config change
--strict both Warnings exit 1
--json check Diagnostics as JSON

Each diagnostic has a level, a code, and namespace, locale, key, file. The text output, and its counts, have one line per problem, naming its first keys; --json lists them all.

Code Level
invalid-syntax error
invalid-resource error
key-conflict error: a key written twice, or also a group
param-mismatch error
unknown-format error
missing-file error in the source locale, else warning
missing-translation warning
missing-param warning: a param or markup left out
missing-plural warning: a plural form left out
unknown-key warning
namespace-name warning: the name is no identifier
import { parla } from '@parlajs/compiler/vite';
export default defineConfig({ plugins: [parla(), react()] });
Option
root Folder holding the config; default Vite’s root. An owner package’s, in a monorepo
config Config file, relative to root

It builds on start and on every catalog or config change, so a Vite app needs no parla build --watch. Errors fail vite build, and show in the overlay in dev. Custom formats go in the config’s formats.

@parlajs/compiler exports build, loadConfig, compileMessage, defineConfig, defaultFormats and the FormatAdapter type:

import { build, formatDiagnostic } from '@parlajs/compiler';
const { diagnostics, written } = await build({ cwd: 'packages/i18n', write: false });