SayKit
Core Concepts

Configuration

The saykit.config.ts file, locales, buckets, formatters, transformers

Every SayKit project has a saykit.config.ts (or .js) at its root: the locales, which files to extract from, and where translations live.

saykit.config.ts
import { defineConfig } from '@saykit/config';
import po from '@saykit/format-po';
import js from '@saykit/transform-js';
import jsx from '@saykit/transform-jsx';

export default defineConfig({
  locales: ['en', 'fr', 'ja'],
  buckets: [
    {
      include: ['src/**/*.{ts,tsx}'],
      output: 'src/locales/{locale}.{extension}',
      formatter: po(),
      transformer: [js(), jsx()],
    },
  ],
});

defineConfig() only types the config. It is validated when the CLI or a bundler plugin loads it, so a mistake fails with a clear error.

Loading

The CLI and plugins search up from the working directory for saykit.config.{ts,mts,cts,js,mjs,cjs}. The file runs as it is on disk, so relative imports resolve against it. Relative paths inside the config (include, exclude, output) resolve against its folder, not the working directory:

saykit.config.ts
import { yaml } from './yaml-formatter.ts';

TypeScript needs Node 22.18+, or Bun, Deno or tsx. Use real extensions in relative imports (.ts, not .js), and only erasable syntax: no enums, namespaces or parameter properties.

Top-level schema

Prop

Type

Locales

Locales are plain strings, BCP 47 or otherwise; whatever you write is the key everywhere.

The first is the source locale: the language your code is written in, and the only catalogue extraction writes. Other locales are left to your translators or TMS.

Reordering locales so another entry is first makes SayKit treat your source messages as that locale. Decide early.

Fallback locales

Non-source catalogues hold only their real translations. When a locale's module is compiled, an untranslated key is filled from a fallback chain, which ends at the source locale. A translation flagged fuzzy counts as untranslated until someone confirms it. fallbackLocales adds steps before it:

saykit.config.ts
export default defineConfig({
  locales: ['en', 'en-GB', 'en-NZ', 'es-MX', 'es'],
  fallbackLocales: {
    'en-NZ': ['en-GB'], // en-NZ → en-GB → en
    'es-MX': 'es', // es-MX → es → en
  },
  buckets: [/* … */],
});

The chain is merged at compile time, so the runtime still loads one module per locale and never sees a missing message.

Buckets

A bucket is "these files in, this catalogue out". Most projects have one; add more when parts of the app want their own files, such as transactional emails beside a UI.

Prop

Type

Output

{locale} is each locale and {extension} the formatter's extension:

output: 'src/locales/{locale}.{extension}';
// → src/locales/en.po, compiled to src/locales/en.js

output: 'translations/{locale}/messages.{extension}';
// → translations/en/messages.po, compiled to translations/en/messages.js

The compiled module is written beside the catalogue as .js, so a formatter whose extension is .js is refused.

Declared messages

A string with no call site, such as a browser extension manifest, a store listing or an email subject, can be declared on the bucket:

messages: {
  extensionName: 'Reading Time',
  extensionDescription: {
    message: 'Estimate how long a page will take to read.',
    context: 'store',
    comments: ["The extension's one-line store description."],
  },
},

The key is the id. Declared messages are merged in on every saykit extract; if a call site uses the same id, the declaration wins on text and comments. They have no source reference, so use comments to say where they appear.

Formatters and transformers

A formatter reads and writes one catalogue format: @saykit/format-po (the default), @saykit/format-json, or your own.

A transformer extracts and rewrites macros for one source language. @saykit/transform-js covers .js/.ts and @saykit/transform-jsx covers .jsx/.tsx; pass both as an array, and each takes the files its match() accepts. You can write your own.

Next

On this page