Skip to content

parla.config.ts

Node imports it directly, with type stripping: no loader.

import { defineConfig } from '@parlajs/compiler';
export default defineConfig({
locales: ['en', 'it', 'de'],
sourceLocale: 'en',
fallbacks: { de: ['en'] },
outDir: 'src/parla',
namespaces: { checkout: { format: 'mf2', path: 'locales/{locale}/checkout.json' } },
functions: { capitalize: 'string' },
markup: ['strong', 'br'],
});
Option Type Default
locales string[]: tags, pt-BR and not pt_BR [sourceLocale]
sourceLocale string, one of locales 'en'
fallbacks Record<locale, locale[]>, for keys and Intl {}, see Fallbacks
outDir Relative to the config, with no catalog in it 'src/parla'
namespaces Record<name, { format, path }> {}
functions Record<name, 'string' | 'number' | 'date'> {}
markup string[]: tags a call may leave out []
formats Record<name, FormatAdapter> {}; icu and mf2 are built in
runtime Module the types import and augment The adapter in package.json, else @parlajs/core
Field
format 'icu', 'mf2' or a key of formats
path Catalog path relative to the config, with a {locale} token

A name is letters, digits, _, - or inner dots; prefer an identifier (Names). A catalog maps keys to messages or groups, in JSON or whatever the format’s parseFile reads.

A config may list them from disk; --watch and the Vite plugin load it again when a catalog is added to, or removed from, a folder that already holds one:

import { readdirSync } from 'node:fs';
const files = readdirSync(new URL('locales/en', import.meta.url)).filter((f) =>
f.endsWith('.json'),
);
export default defineConfig({
namespaces: Object.fromEntries(
files.map((f) => [f.slice(0, -5), { format: 'icu', path: `locales/{locale}/${f}` }]),
),
});

Each value types the param; createParla({ functions }) implements each. See Your own functions.

Tags createParla({ markup }) renders. See Rich text.

Extra syntaxes, keyed by the name a namespace’s format gives. The CLI, the Vite plugin and x18n read them here. See Writing a format adapter.