0.1.0-alpha.7

@zerolith/i18n/compile

Import from @zerolith/i18n/compile. Generated from the source; every signature below is what the published types declare.

Functions

compileMessages

function compileMessages(locale: string, catalog: Catalog, options?: CompileOptions): CompiledCatalog

Compiles one locale's catalog into a module: locale, one exported function per message named from its key, and the Intl helpers they share. Each function takes an args object typed from the message's placeholders, or nothing when the message has none. A formatter whose options are all literals is a module-level binding created on first use and shared by every message that formats the same way; options that read an argument find their formatter in a cache keyed by the options. Only the helpers the messages use are written.

Source: packages/i18n/src/compile.ts:946

messageNames

function messageNames(catalog: Catalog): string[]

The keys of a catalog as function names, for comparing locales.

Source: packages/i18n/src/compile.ts:1012

compileIndex

function compileIndex(locales: readonly string[], options?: CompileOptions): string

The index module for a set of locales: the list of locales and one lazy loader per locale, so each locale is its own chunk.

Source: packages/i18n/src/compile.ts:1021

Interfaces

CompileOptions

interface CompileOptions

Options for compileMessages.

  • language?: "ts" | "js": ts emits TypeScript (the default); js emits JavaScript with JSDoc types for buildless projects.
  • source?: string: Named in the generated header.

Source: packages/i18n/src/compile.ts:16

CompiledCatalog

interface CompiledCatalog

The result of compiling one catalog.

  • code: string: The generated module's source, TypeScript or JavaScript as the language option chose; the zerolith-i18n CLI writes it to <locale>.ts or <locale>.js.
  • names: string[]: The message keys as function names, in source order.

Source: packages/i18n/src/compile.ts:25

Types

Catalog

type Catalog = Readonly<Record<string, string>>

A catalog: message key to MessageFormat 2 source.

Source: packages/i18n/src/compile.ts:13