SayKit
Core Concepts

Architecture

How SayKit's runtime, config, transformers, formatters, and plugins fit together

SayKit is a few small pieces that compose. Everything else in the docs hangs off this picture.

The pieces

Runtime

createCatalogue, createView, createStore. A catalogue holds locales, a view formats one, a store switches between them.

Config and CLI

A typed saykit.config.ts, and the saykit CLI that extracts and compiles catalogues.

Transformer

Parses a source language: extracts messages, and rewrites macros to runtime calls.

Formatter

Reads and writes a catalogue format, PO by default.

Plugin

Runs the transformer in your build. unplugin-saykit for Vite and friends, babel-plugin-saykit for Babel.

How they fit together

 source.ts ──saykit extract──▶ locales/en.po ──saykit plugin──▶ locales/en.js
 (macros)    transformer +     (translators     formatter +       (data your
              formatter         edit these)      ICU compiler       app imports)

 source.ts ──bundler + saykit plugin──▶ say.call({ id: 'Zk1aQv', _name: name })
  1. Extract. The CLI walks each bucket's files, the transformer finds the macros, and the formatter writes the source locale's catalogue. Other locales are never touched, so translations are never overwritten.
  2. Compile. The CLI reads each locale's catalogue, fills untranslated keys from its fallback chain, and compiles every ICU message to data with its number and date formats resolved. The build plugin does this when the build starts and again in dev whenever a catalogue changes; extract ends by doing it, and saykit compile does it alone.
  3. Build. The plugin rewrites each macro into a say.call(...) with the message's id and values. A locale module is an ordinary .js import your bundler already knows how to load, split and hot-reload.

Identifiers

Every message gets a 6-character hash of its ICU text and context:

sha256("Hello, {name}!" + context)  →  "Zk1aQv"

The same text and context always give the same id, so moving a message between files or reformatting it changes nothing. A descriptor can set a readable id instead.

What ships

  • the saykit runtime, with no dependencies, and whichever integration you use
  • the say.call(...) calls the plugin wrote
  • the locale modules you import

A locale module is plain data, with nothing left to parse, so the only formatting code that ships is a small evaluator over Intl. Being data is also what lets a server hand a locale to a client as JSON. Locales you never import never reach your bundle.

Where to next?

On this page