stdout-design_

Internationalization

Locale-aware templates, per-locale translation files, RTL support, and per-locale fonts.

stdout-design treats locale as a first-class concept. The same template can render in every language you configure same props shape, different string values with RTL handled by the renderer.

Configuration

Declare the locales you support in studio.config.ts:

const config: StudioConfig = {
  locales: ["en", "ar"],
  // ...
};

The CLI and studio then expose these locales (CLI --locale en,ar, studio locale tabs), and every render's ctx.locale says which one it is.

Translation files

Create one JSON file per locale under locales/, keyed by template ID:

// locales/en.json
{
  "stat-card": {
    "title": "Milestone",
    "label": "and counting"
  },
  "bento-features": {
    "feature_one_title": "Deep Work",
    "feature_one_subtitle": "Uninterrupted focus sessions."
  }
}
// locales/ar.json
{
  "stat-card": {
    "title": "إنجاز",
    "label": "والعدد في ازدياد"
  },
  "bento-features": {
    "feature_one_title": "العمل العميق",
    "feature_one_subtitle": "جلسات تركيز بدون أي مقاطعات."
  }
}

The top-level key is the template ID; its value is a set of prop overrides.

Merge rules

When rendering locale ar, the current template's section is merged into the props, following the schema:

  • Text fields (field.text) are replaced, at any depth: inside field.object groups and inside each item of a field.list.
  • Everything else stays: colors, numbers, booleans, selects, and text marked translatable: false (URLs, brand names, prices).
  • List lengths never change. A translation covers the items it lists, by position; extra items are ignored and missing ones keep their value.
  • Unknown keys are ignored. Locale data never adds props.
  • Translations are validated like any other content, so a translation that breaks a field's max fails the render with a PropValidationError naming the field.
// locales/ar.json: only the labels change; the amounts aren't translatable
{
  "bento-feature": {
    "receipt": [{ "item": "قهوة" }, { "item": "بقالة" }, { "item": "مترو" }]
  }
}

Templates written before defineTemplate keep the older rule: a top-level string replaces a string, and an array replaces an array.

Right-to-left

Each locale maps to a script and a direction: Arabic, Persian, Urdu, Pashto, Sindhi, Uyghur, and Kurdish (Sorani) are Arabic script; Hebrew and Yiddish are Hebrew script; both run right to left. An explicit script subtag (az-Arab, ku-Latn) wins over the language.

The root element of every render gets dir and lang, so these mirror without any code:

  • flex rows and text alignment
  • logical CSS properties: insetInlineStart/insetInlineEnd, marginInlineStart/marginInlineEnd, paddingInlineStart/paddingInlineEnd, borderInlineStart/borderInlineEnd

Physical left/right don't mirror; use them only for things that shouldn't, like a label printed on a drawn object. For what CSS can't mirror, ctx.flip(value) negates a value in right-to-left renders:

<div style={{ transform: `rotate(${ctx.flip(-6)}deg)` }} />

Wrap brand names and numbers like +18% in <span dir="ltr"> to keep bidi from reordering them.

Typography

ctx.type(spec) takes a text style written for Latin and adapts it to the render's script:

<span
  style={ctx.type({
    font: "display",
    size: 96,
    leading: 0.9,
    tracking: -0.04,
    uppercase: true,
  })}
>
  {props.headline}
</span>
ScriptSizeLine heightLetter spacing, italics, uppercase
Latinas givenas givenapplied
Arabic× 0.88at least 1.15dropped
Hebrew× 0.94at least 1.05dropped

Leave size out to adapt only the styling. When a face doesn't suit the table, set exact values for one script: scripts: { arabic: { size: 100, leading: 1 } }.

Fonts

A template declares its fonts by role, Latin face first:

export default defineTemplate({
  fonts: {
    display: { faces: ["Archivo Black", "Lalezar"] },
    body: { faces: [{ family: "IBM Plex Sans Arabic", weights: [400, 700] }] },
  },
  // ...
});

ctx.fonts.display is then "Archivo Black, Lalezar, sans-serif": a glyph the first face lacks falls through to the next. Every declared face loads from Google Fonts on every locale, once per process.

A render's fonts are, in order:

  1. the fonts entry in studio.config.ts for the locale (or default, for Latin locales without one)
  2. the template's declared faces, except any family the config already loads, so the config can swap in a local file
  3. for an Arabic- or Hebrew-script locale with no config entry, Noto Sans Arabic or Noto Sans Hebrew, unless the template names it

To override a family with a local file:

const config: StudioConfig = {
  fonts: {
    ar: [
      {
        family: "Lalezar",
        path: "./fonts/Lalezar-Regular.ttf",
        source: "local",
        weights: [400],
      },
    ],
  },
};

Each font entry supports:

FieldDescription
familyFont family name, as the template names it
pathPath to a local font file (.ttf/.woff2); required when source: "local"
source"local" or "google" (default)
weightsFont weights to load (e.g. [400, 700])

Rendered images are cached per locale and font set, so switching languages in the studio doesn't re-fetch fonts, and changing fonts never serves an image rendered with the old ones.

Rendering across locales

# One command, every locale × every preset
studio render stat-card --data data/stats.csv --locale en,ar --preset instagram-square,x-card --out-dir out

Each locale produces its own set of files stat-card.en.instagram-square.0.png, stat-card.ar.instagram-square.0.png, and so on. See Batch Rendering for the full matrix behavior.

On this page