mix gettext_ts.codegen (gettext_ts v0.2.0)

Copy Markdown View Source

Generates typed TypeScript catalogs from the Gettext PO tree.

Output (under :output_path):

  • catalog/<locale>/<domain>.ts — one file per locale AND domain. The unit of loading is the domain, not the locale: an application whose admin copy outweighs its public copy would otherwise ship the admin catalog to every visitor who never sees the admin.
  • index.tslocales, domains, Locale/Domain/TranslationKey types, loadCatalog(locale, domains?) (dynamic imports, one per chunk), and createT with %{var} interpolation and an overrides layer for runtime-edited translations.
  • react.tsx — provider + useT(domain?) hook (unless react: false). The provider takes a domains prop (which chunks to load) and an optional initialCatalog so a server-rendered route tree is already translated before hydration.

The source locale gets no files. Its catalog is identity by construction — msgid IS the copy — and createT already falls back to the msgid, so writing it out is handing the copy back to itself in a file the browser then has to download. A source locale with real PO files on disk is read and emitted like any other.

Files are only written when content changed, so --check in CI is cheap. Stale files under catalog/ are removed (and reported by --check): the directory is generated output, and a renamed domain must not leave a catalog behind that still type-checks.