Tanguv0.35.0
Text & i18n42 exports
Raw Markdown

/i18n

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

(use /i18n)

Structs#

Bundle#

struct

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

FieldTypeDefaultConstraints / Notes
default-localeString——
localesMap——
fallbacksMap——

Constants#

*bundle*#

constant · Any

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

Value:none

*locale*#

constant · Any

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

Value:"en"

Functions & symbols#

Bundle-construct#

constructor
(Bundle-construct input ...rest)

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

ParameterTypeOptionalDescription
inputAnyrequired—
restAnyoptional—
Returns:Any

canonical-locale#

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

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

ParameterTypeOptionalDescription
tagStringrequiredBCP 47 locale tag
Returns:Any
(i18n/canonical-locale "en_us") ; -> "en-US"

clear-registered-bundles!#

function
(clear-registered-bundles!)

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

Returns:Any

current-bundle#

function
(current-bundle)

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

Returns:Any

current-language#

function
(current-language)

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

Returns:Any

current-locale#

function
(current-locale)

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

Returns:Any

fold-case#

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

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

ParameterTypeOptionalDescription
sStringrequiredInput string
localeStringoptionalOptional BCP 47 locale (e.g. "tr" Turkic case folding)
Returns:Any
(i18n/fold-case "Straße")

format#

function
(i18n/format value) -> String

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

ParameterTypeOptionalDescription
valueAnyrequiredNumber, /chrono temporal/duration value, or Array/List
locale-or-optsAnyrequiredOptional BCP 47 locale tag or options Map
Returns:Any
(i18n/format 1234567.89d "el-GR")
(i18n/format ["Αθήνα" "Θεσσαλονίκη"] "el")

format-date-time#

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

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

ParameterTypeOptionalDescription
temporalAnyrequired/chrono Date, Time, Date-Time, Zoned-Date-Time, Instant, or ISO String
locale-or-optsAnyrequiredOptional BCP 47 locale tag or options Map (:style, :date-style, :time-style, :fields, :calendar, :hour-cycle, :time-zone, :time-zone-name)
Returns:Any
(i18n/format-date-time (chrono/Date 2025 3 25) {:locale "el-GR" :style :long})

format-display-name#

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

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

ParameterTypeOptionalDescription
codeStringrequiredLanguage, region, script, or currency subtag code
kindKeySymboloptionalEntity kind (:language, :region, :script, :currency)
optionsMapoptionalOptional {:locale ... :style :long|:short}
Returns:Any
(i18n/format-display-name "JP" :region {:locale "fr"})

format-duration#

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

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

ParameterTypeOptionalDescription
durationAnyrequired/chrono Duration, Span, or unit Map
locale-or-optsAnyrequiredOptional locale tag or options Map (:style :long | :short | :narrow | :digital)
Returns:Any
(i18n/format-duration {:hours 2 :minutes 45} {:locale "el" :style :long})

format-list#

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

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

ParameterTypeOptionalDescription
itemsArrayrequiredSequence of items to join
locale-or-optsAnyrequiredOptional locale tag or {:type :conjunction | :disjunction | :unit :style :long | :short | :narrow}
Returns:Any
(i18n/format-list ["Αθήνα" "Πάτρα" "Κρήτη"] "el")

format-number#

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

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

ParameterTypeOptionalDescription
nNumberrequiredNumeric value (Dec, Int, Float, or U8)
locale-or-optsAnyrequiredOptional BCP 47 locale tag or options Map (:style, :currency, :notation, :min-scale, :max-scale, :grouping, :sign-display, :rounding-mode)
Returns:Any
(i18n/format-number 1234.5d {:locale "el-GR" :style :currency :currency "EUR"})
(i18n/format-number 1250000 {:locale "en-US" :notation :compact})

format-relative#

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

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

ParameterTypeOptionalDescription
deltaAnyrequiredSigned integer delta, /chrono Span/Duration, or temporal value
unitSymbolrequiredTime unit (:year, :month, :week, :day, :hour, :minute, :second)
Returns:Any
(i18n/format-relative -1 :day "el")

graphemes#

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

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

ParameterTypeOptionalDescription
textStringrequiredInput UTF-8 string
Returns:Any
(i18n/graphemes "👨‍👩‍👧‍👦🇬🇷")

locale-comparator#

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

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

ParameterTypeOptionalDescription
localeStringoptionalOptional BCP 47 locale
optionsMapoptionalCollation options {:strength :numeric :case-first}
Returns:Any
(sort names (i18n/locale-comparator "el"))

locale-compare#

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

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

ParameterTypeOptionalDescription
aStringrequiredFirst string
bStringrequiredSecond string
locale-or-optsAnyrequiredOptional locale tag or {:sensitivity :base | :accent | :case | :variant :numeric true}
Returns:Any
(i18n/locale-compare "α" "ά" {:locale "el" :sensitivity :base})

locale-sort#

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

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

ParameterTypeOptionalDescription
itemsArrayrequiredSequence of strings, maps, or structs to sort
locale-or-optsAnyrequiredOptional locale tag or {:locale ... :key :field :reverse false :numeric true}
Returns:Any
(i18n/locale-sort ["Ωμέγα" "Αθήνα" "Άρτα"] "el")

localize-field#

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

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

ParameterTypeOptionalDescription
entityAnyrequired—
fieldAnyrequired—
restAnyoptional—
Returns:Any

maximize-locale#

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

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

ParameterTypeOptionalDescription
tagStringrequiredBCP 47 locale tag
Returns:Any
(i18n/maximize-locale "el") ; -> "el-Grek-GR"

minimize-locale#

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

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

ParameterTypeOptionalDescription
tagStringrequiredBCP 47 locale tag
Returns:Any
(i18n/minimize-locale "en-Latn-US") ; -> "en"

parse-locale#

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

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

ParameterTypeOptionalDescription
tagAnyrequiredBCP 47 locale tag string or symbol
Returns:Any
(i18n/parse-locale "el-GR-u-ca-gregory-hc-h23")

plural#

function
(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.

ParameterTypeOptionalDescription
nNumberrequiredItem count
forms-mapMaprequiredMap of CLDR plural categories (:zero, :one, :other, etc.) or singular noun
Returns:Any
(i18n/plural 5 "μήνυμα" "μηνύματα" "el")

plural-category#

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

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

ParameterTypeOptionalDescription
nNumberrequiredCount or ordinal value
locale-or-optsAnyrequiredOptional locale tag or {:locale ... :type :cardinal | :ordinal}
Returns:Any
(i18n/plural-category 1 "el")

register-bundle#

function
(register-bundle ns bundle)

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

ParameterTypeOptionalDescription
nsAnyrequired—
bundleAnyrequired—
Returns:Any

registered-bundle#

function
(registered-bundle ns)

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

ParameterTypeOptionalDescription
nsAnyrequired—
Returns:Any

segment#

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

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

ParameterTypeOptionalDescription
textStringrequiredUTF-8 string to segment
localeStringoptionalOptional BCP 47 locale
Returns:Any
(i18n/segment "café 👨‍👩‍👧")

sentences#

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

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

ParameterTypeOptionalDescription
textStringrequiredInput prose string
localeStringoptionalOptional BCP 47 locale
optionsMapoptionalSegmentation options
Returns:Any
(i18n/sentences "Hello world. Next sentence!")

strip-accents#

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

Removes combining diacritical marks via NFD decomposition and NFC recomposition.

ParameterTypeOptionalDescription
sStringrequiredInput string
Returns:Any
(i18n/strip-accents "Καλημέρα Αθήνα café")

t#

function
(t key ...rest)

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

ParameterTypeOptionalDescription
keyAnyrequired—
restAnyoptional—
Returns:Any

t-html#

function
(t-html key ...rest)

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

ParameterTypeOptionalDescription
keyAnyrequired—
restAnyoptional—
Returns:Any

to-locale-lower-case#

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

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

ParameterTypeOptionalDescription
sStringrequiredInput string
localeStringoptionalOptional BCP 47 locale (handles Turkish İ/ı, Greek sigma)
Returns:Any
(i18n/to-locale-lower-case "İSTANBUL" "tr")

to-locale-title-case#

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

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

ParameterTypeOptionalDescription
sStringrequiredInput string
localeStringoptionalOptional BCP 47 locale
Returns:Any
(i18n/to-locale-title-case "hello world" "en")

to-locale-upper-case#

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

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

ParameterTypeOptionalDescription
sStringrequiredInput string
localeAnyrequiredOptional BCP 47 locale (e.g. "el" strips Greek tonos in all-caps, "tr" maps i -> İ)
Returns:Any
(i18n/to-locale-upper-case "Καλημέρα Ελλάδα" "el")

unregister-bundle#

function
(unregister-bundle ns)

Removes any registered bundle for namespace `ns`.

ParameterTypeOptionalDescription
nsAnyrequired—
Returns:Any

validate-bundle#

function
(validate-bundle bundle)

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

ParameterTypeOptionalDescription
bundleAnyrequired—
Returns:Any

validate-registered-bundles#

function
(validate-registered-bundles)

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

Returns:Any

week-info#

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

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

ParameterTypeOptionalDescription
localeStringoptionalOptional BCP 47 locale (defaults to `*locale*`)
Returns:Any
(i18n/week-info "en-US")

words#

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

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

ParameterTypeOptionalDescription
textStringrequiredInput UTF-8 string
Returns:Any
(i18n/words "Καλημέρα κόσμε!")

Related modules