# std/i18n

Typed translations as a generator library.

```vyrn
import { i18n } from "std/i18n"
import { t, setLocale, locale, Locale, TransKey, tCartItems } from i18n("./locales")

```

`i18n(dir)` reads every `<locale>.json` under `dir` at compile time, checks that the locales agree, compiles each ICU message to a Vyrn function body and returns the module as source text (`vyrn emit-gen <file>` shows it). The module holds `Locale` (one variant per file), `setLocale`/`locale`, `TransKey` (the finite type of every dotted key), one function per key with arguments taken from the message and the base-locale message as its doc, `t(key)`, and `transKey(s)`, which checks a runtime `String` against the key set.

The ICU subset: plain text; `{name}` (String); `{n, plural, ...}` (Int64, `#` is the number, `other` required); `{k, select, ...}` (a finite string type of the branch names). `''` is a literal apostrophe, `'{'` and `'}'` literal braces. An argument name may not start with `__`. Numbers, booleans and null in a locale file, and a plural or select nested in a branch, fail generation.

## i18n

`fn`, at line 971.

```vyrn
gen fn i18n(dir: String) -> String
```

Read every `<locale>.json` under `dir`, check the locales, and return the translation module's source.

---

From https://vyrn-lang.github.io/docs/std/i18n.html — generated by `site/export.vyrn` from the Vyrn repository.
