API reference@evolu/commonType › localizeTypes

const localizeTypes: LocalizeTypes;

Defined in: packages/common/src/Type.ts:1043

Creates localized copies of selected Type declarations.

Pass the Types used together in one localization scope and formatter maps keyed by locale. TypeScript infers every formatter required by the selected Types, including errors from nested structural Types and recursive Lazy Types. Every locale must provide the complete inferred formatter set; missing and unrelated formatters are compile-time errors.

The result preserves the locale names, selected Type names, and exact TypeScript types. A localized Type validates exactly like its source Type; only its human-readable formatError and Standard Schema messages change. The source Types remain unchanged.

Parents and reflected child Types are localized with the same formatter set. Structural Types retain error paths and delegate nested messages to the Type that produced them. Different localized Type sets can coexist in separate application or dependency-injection scopes.

Localization is scoped to the selected Types instead of a package-wide translation registry. Static imports give bundlers an explicit dependency graph, so unrelated Types, locales, and formatters can be removed. Bundling every locale an app supports also allows language changes without a network connection.

The selected Type map, locale map, and formatter maps must be plain objects with own enumerable string-keyed data properties.

Example

import { String, localizeTypes, minLength } from "@evolu/common";
import { cs } from "@evolu/common/intl";

const Label = minLength(1)(String);

const typesByLocale = localizeTypes(
  { Label },
  {
    cs: {
      MinLength1: cs.formatMinLengthError,
      String: cs.formatStringError,
    },
  },
);

expectTypeOf<typeof typesByLocale.cs.Label>().toEqualTypeOf<typeof Label>();

const result = typesByLocale.cs.Label.fromUnknown("");
expectErr(result, { type: "MinLength1", min: 1, value: "" });
expect(typesByLocale.cs.Label.formatError(result.error)).toBe(
  "Text nesmí být prázdný.",
);

Supported locales

English is built in; use Type directly for its default formatters. The following additional locales are available:

  • Arabic (ar)
  • Bengali (bn)
  • Catalan (ca)
  • Chinese, Simplified (zhCN)
  • Chinese, Traditional (zhTW)
  • Croatian (hr)
  • Czech (cs)
  • Danish (da)
  • Dutch (nl)
  • Filipino (fil)
  • Finnish (fi)
  • French (fr)
  • German (de)
  • Greek (el)
  • Hebrew (he)
  • Hindi (hi)
  • Hungarian (hu)
  • Indonesian (id)
  • Italian (it)
  • Japanese (ja)
  • Korean (ko)
  • Malay (ms)
  • Malayalam (ml)
  • Marathi (mr)
  • Norwegian Bokmål (nb)
  • Persian (fa)
  • Polish (pl)
  • Portuguese (pt)
  • Portuguese, Brazilian (ptBR)
  • Punjabi (pa)
  • Romanian (ro)
  • Slovak (sk)
  • Slovenian (sl)
  • Spanish (es)
  • Swahili (sw)
  • Swedish (sv)
  • Tamil (ta)
  • Telugu (te)
  • Thai (th)
  • Turkish (tr)
  • Ukrainian (uk)
  • Urdu (ur)
  • Vietnamese (vi)