# Module /i18n

Unicode CLDR internationalization powered by ICU4X: locale-aware numbers, currencies, dates, plurals, collation, and grapheme segmentation.

```tangu
(use /i18n)
```

## Structs

### Bundle

`Struct` in `/i18n`

Structured i18n translation bundle with normalized locale catalogs and explicit fallbacks.

| Field | Type | Default | Notes |
| :--- | :--- | :--- | :--- |
| `default-locale` | `String` | `—` | — |
| `locales` | `Map` | `—` | — |
| `fallbacks` | `Map` | `—` | — |

## Constants

### *bundle*

`Constant (Any)`

Active ICU/catalog translation bundle dynamically scoped via `let-ds`.

### *locale*

`Constant (Any)`

Active BCP 47 locale tag dynamically scoped via `let-ds` (default `"en"`).

## Functions & symbols

### Bundle-construct

`(Bundle-construct input ...rest)`

Constructs a normalized `Bundle` from `{:en {...} :el {...}}` (plus optional opts)
or `{:default-locale "en" :locales {...} :fallbacks {...}}`.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `input` | `Any` | no | — |
| `rest` | `Any` | yes | — |

### canonical-locale

`(i18n/canonical-locale tag) -> String`

Normalizes a BCP 47 locale tag to CLDR canonical capitalization and subtag form.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `tag` | `String` | no | BCP 47 locale tag |

```tangu
(i18n/canonical-locale "en_us") ; -> "en-US"
```

### clear-registered-bundles!

`(clear-registered-bundles!)`

Clears all entries from the global bundle registry (intended for isolated test suites).

### current-bundle

`(current-bundle)`

Returns the currently bound translation bundle from dynamic scope (or ()).

### current-language

`(current-language)`

Returns the normalized lowercase base language subtag (e.g. "el-GR" -> "el").

### current-locale

`(current-locale)`

Returns the active locale tag from dynamic scope, defaulting to "en".

### fold-case

`(i18n/fold-case s [locale]) -> String`

Applies Unicode case folding for locale-consistent case-insensitive matching.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `s` | `String` | no | Input string |
| `locale` | `String` | yes | Optional BCP 47 locale (e.g. "tr" Turkic case folding) |

```tangu
(i18n/fold-case "Straße")
```

### format

`(i18n/format value) -> String`

Polymorphically formats numbers, /chrono temporal and duration values, and sequences according to locale rules.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `value` | `Any` | no | Number, /chrono temporal/duration value, or Array/List |
| `locale-or-opts` | `Any` | no | Optional BCP 47 locale tag or options Map |

```tangu
(i18n/format 1234567.89d "el-GR")
(i18n/format ["Αθήνα" "Θεσσαλονίκη"] "el")
```

### format-date-time

`(i18n/format-date-time temporal [locale-or-opts]) -> String`

Formats a /chrono temporal value according to CLDR calendar and locale conventions.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `temporal` | `Any` | no | /chrono Date, Time, Date-Time, Zoned-Date-Time, Instant, or ISO String |
| `locale-or-opts` | `Any` | no | Optional BCP 47 locale tag or options Map (:style, :date-style, :time-style, :fields, :calendar, :hour-cycle, :time-zone, :time-zone-name) |

```tangu
(i18n/format-date-time (chrono/Date 2025 3 25) {:locale "el-GR" :style :long})
```

### format-display-name

`(i18n/format-display-name code [kind [options]]) -> String`

Formats localized CLDR display names for languages, regions, scripts, and currencies.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `code` | `String` | no | Language, region, script, or currency subtag code |
| `kind` | `KeySymbol` | yes | Entity kind (:language, :region, :script, :currency) |
| `options` | `Map` | yes | Optional {:locale ... :style :long|:short} |

```tangu
(i18n/format-display-name "JP" :region {:locale "fr"})
```

### format-duration

`(i18n/format-duration duration [locale-or-opts]) -> String`

Formats a /chrono Duration, Span, or unit Map into localized unit lists or digital clock notation.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `duration` | `Any` | no | /chrono Duration, Span, or unit Map |
| `locale-or-opts` | `Any` | no | Optional locale tag or options Map (:style :long | :short | :narrow | :digital) |

```tangu
(i18n/format-duration {:hours 2 :minutes 45} {:locale "el" :style :long})
```

### format-list

`(i18n/format-list items [locale-or-opts]) -> String`

Formats a sequence of items using locale-specific list conjunctions or disjunctions.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `items` | `Array` | no | Sequence of items to join |
| `locale-or-opts` | `Any` | no | Optional locale tag or {:type :conjunction | :disjunction | :unit :style :long | :short | :narrow} |

```tangu
(i18n/format-list ["Αθήνα" "Πάτρα" "Κρήτη"] "el")
```

### format-number

`(i18n/format-number n [locale-or-opts]) -> String`

Formats a number with locale-specific grouping, decimal separators, currency symbols, percentages, or compact notation.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `n` | `Number` | no | Numeric value (Dec, Int, Float, or U8) |
| `locale-or-opts` | `Any` | no | Optional BCP 47 locale tag or options Map (:style, :currency, :notation, :min-scale, :max-scale, :grouping, :sign-display, :rounding-mode) |

```tangu
(i18n/format-number 1234.5d {:locale "el-GR" :style :currency :currency "EUR"})
(i18n/format-number 1250000 {:locale "en-US" :notation :compact})
```

### format-relative

`(i18n/format-relative delta unit [locale-or-opts]) -> String`

Formats relative time phrases such as "yesterday", "χθες", or "in 3 hours".

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `delta` | `Any` | no | Signed integer delta, /chrono Span/Duration, or temporal value |
| `unit` | `Symbol` | no | Time unit (:year, :month, :week, :day, :hour, :minute, :second) |

```tangu
(i18n/format-relative -1 :day "el")
```

### graphemes

`(i18n/graphemes text [locale]) -> Array`

Segments a string into an Array of UAX #29 extended grapheme clusters.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `text` | `String` | no | Input UTF-8 string |

```tangu
(i18n/graphemes "👨‍👩‍👧‍👦🇬🇷")
```

### locale-comparator

`(i18n/locale-comparator [locale [options]]) -> Func`

Returns a 2-argument comparator function sorting strings according to UCA/CLDR locale collation rules.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `locale` | `String` | yes | Optional BCP 47 locale |
| `options` | `Map` | yes | Collation options {:strength :numeric :case-first} |

```tangu
(sort names (i18n/locale-comparator "el"))
```

### locale-compare

`(i18n/locale-compare a b [locale-or-opts]) -> Int`

Compares two strings using the Unicode Collation Algorithm, returning -1, 0, or 1.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `a` | `String` | no | First string |
| `b` | `String` | no | Second string |
| `locale-or-opts` | `Any` | no | Optional locale tag or {:sensitivity :base | :accent | :case | :variant :numeric true} |

```tangu
(i18n/locale-compare "α" "ά" {:locale "el" :sensitivity :base})
```

### locale-sort

`(i18n/locale-sort items [locale-or-opts]) -> Array`

Returns a new sequence sorted by locale collation rules, supporting :key and :reverse.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `items` | `Array` | no | Sequence of strings, maps, or structs to sort |
| `locale-or-opts` | `Any` | no | Optional locale tag or {:locale ... :key :field :reverse false :numeric true} |

```tangu
(i18n/locale-sort ["Ωμέγα" "Αθήνα" "Άρτα"] "el")
```

### localize-field

`(localize-field entity field ...rest)`

Resolves a localized field from a domain entity (`entity:names`, `entity:field` map, `field-<lang>`, or fallback string).

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `entity` | `Any` | no | — |
| `field` | `Any` | no | — |
| `rest` | `Any` | yes | — |

### maximize-locale

`(i18n/maximize-locale tag) -> String`

Applies CLDR likely-subtags maximization to infer missing script and region subtags.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `tag` | `String` | no | BCP 47 locale tag |

```tangu
(i18n/maximize-locale "el") ; -> "el-Grek-GR"
```

### minimize-locale

`(i18n/minimize-locale tag) -> String`

Applies CLDR likely-subtags minimization to strip redundant script/region subtags.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `tag` | `String` | no | BCP 47 locale tag |

```tangu
(i18n/minimize-locale "en-Latn-US") ; -> "en"
```

### parse-locale

`(i18n/parse-locale tag [opts]) -> Map`

Parses and canonicalizes a BCP 47 locale tag into a Map of subtags and Unicode extension preferences.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `tag` | `Any` | no | BCP 47 locale tag string or symbol |

```tangu
(i18n/parse-locale "el-GR-u-ca-gregory-hc-h23")
```

### plural

`(i18n/plural n forms-map [locale-or-opts]) -> Any`

Selects a localized plural form from a category map or formats a singular/plural noun pair.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `n` | `Number` | no | Item count |
| `forms-map` | `Map` | no | Map of CLDR plural categories (:zero, :one, :other, etc.) or singular noun |

```tangu
(i18n/plural 5 "μήνυμα" "μηνύματα" "el")
```

### plural-category

`(i18n/plural-category n [locale-or-opts]) -> Symbol`

Returns the CLDR plural category (:zero, :one, :two, :few, :many, :other) for a number.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `n` | `Number` | no | Count or ordinal value |
| `locale-or-opts` | `Any` | no | Optional locale tag or {:locale ... :type :cardinal | :ordinal} |

```tangu
(i18n/plural-category 1 "el")
```

### register-bundle

`(register-bundle ns bundle)`

Registers a `Bundle` under namespace `ns` (overwriting any existing entry for `ns`) and returns it.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `ns` | `Any` | no | — |
| `bundle` | `Any` | no | — |

### registered-bundle

`(registered-bundle ns)`

Looks up a previously registered `Bundle` by namespace `ns` (returns `()` if unregistered).

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `ns` | `Any` | no | — |

### segment

`(i18n/segment text [locale]) -> (Array String)`

Splits `text` into UAX #29 extended grapheme clusters.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `text` | `String` | no | UTF-8 string to segment |
| `locale` | `String` | yes | Optional BCP 47 locale |

```tangu
(i18n/segment "café 👨‍👩‍👧")
```

### sentences

`(i18n/sentences text [locale [options]]) -> (Array String)`

Splits `text` into locale-aware sentence boundaries via UAX #29 / ICU4X.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `text` | `String` | no | Input prose string |
| `locale` | `String` | yes | Optional BCP 47 locale |
| `options` | `Map` | yes | Segmentation options |

```tangu
(i18n/sentences "Hello world. Next sentence!")
```

### strip-accents

`(i18n/strip-accents s) -> String`

Removes combining diacritical marks via NFD decomposition and NFC recomposition.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `s` | `String` | no | Input string |

```tangu
(i18n/strip-accents "Καλημέρα Αθήνα café")
```

### t

`(t key ...rest)`

Translates `key` against registered `:ns/key` bundles or dynamic `*bundle*` and `*locale*`.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `key` | `Any` | no | — |
| `rest` | `Any` | yes | — |

### t-html

`(t-html key ...rest)`

Renders a translation message into an `#html`-spliceable fragment Array preserving structured HTML params.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `key` | `Any` | no | — |
| `rest` | `Any` | yes | — |

### to-locale-lower-case

`(i18n/to-locale-lower-case s [locale]) -> String`

Converts `s` to lowercase respecting language-sensitive Unicode/CLDR case rules.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `s` | `String` | no | Input string |
| `locale` | `String` | yes | Optional BCP 47 locale (handles Turkish İ/ı, Greek sigma) |

```tangu
(i18n/to-locale-lower-case "İSTANBUL" "tr")
```

### to-locale-title-case

`(i18n/to-locale-title-case s [locale]) -> String`

Converts `s` to Unicode titlecase using locale-specific case mapping rules.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `s` | `String` | no | Input string |
| `locale` | `String` | yes | Optional BCP 47 locale |

```tangu
(i18n/to-locale-title-case "hello world" "en")
```

### to-locale-upper-case

`(i18n/to-locale-upper-case s [locale]) -> String`

Converts a string to uppercase using locale-specific Unicode case mapping rules.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `s` | `String` | no | Input string |
| `locale` | `Any` | no | Optional BCP 47 locale (e.g. "el" strips Greek tonos in all-caps, "tr" maps i -> İ) |

```tangu
(i18n/to-locale-upper-case "Καλημέρα Ελλάδα" "el")
```

### unregister-bundle

`(unregister-bundle ns)`

Removes any registered bundle for namespace `ns`.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `ns` | `Any` | no | — |

### validate-bundle

`(validate-bundle bundle)`

Validates locale parity across all keys, plural `:other` fallbacks, and `{var}` placeholders.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `bundle` | `Any` | no | — |

### validate-registered-bundles

`(validate-registered-bundles)`

Validates all currently registered bundles with `validate-bundle` and aggregates parity reports.

### week-info

`(i18n/week-info [locale]) -> Map`

Returns CLDR week metadata `{:first-day :mon|:sun ... :weekend [...]}` for `locale`.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `locale` | `String` | yes | Optional BCP 47 locale (defaults to `*locale*`) |

```tangu
(i18n/week-info "en-US")
```

### words

`(i18n/words text [locale-or-opts]) -> Array`

Extracts word-like tokens from a string using UAX #29 word boundary rules.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `text` | `String` | no | Input UTF-8 string |

```tangu
(i18n/words "Καλημέρα κόσμε!")
```
