Skip to content

basalt / i18n/src / I18n

Class: I18n<C> ​

Defined in: i18n/src/i18n.ts:37

Locale-aware translation and formatting. Messages come from typed catalogs (with {param} interpolation and Intl.PluralRules), formatting from the native Intl APIs. The active locale is resolved from the request context, with a fallback chain down to defaultLocale.

Type Parameters ​

C ​

C extends Catalog

Constructors ​

Constructor ​

> new I18n<C>(options): I18n<C>

Defined in: i18n/src/i18n.ts:38

Parameters ​

options ​

I18nOptions<C>

Returns ​

I18n<C>

Methods ​

currency() ​

> currency(value, currency, options?): string

Defined in: i18n/src/i18n.ts:74

Parameters ​

value ​

number

currency ​

string

options? ​

NumberFormatOptions

Returns ​

string


date() ​

> date(value, options?): string

Defined in: i18n/src/i18n.ts:77

Parameters ​

value ​

number | Date

options? ​

DateTimeFormatOptions

Returns ​

string


in() ​

> in(requested): Translator<C>

Defined in: i18n/src/i18n.ts:47

A translator pinned to an explicit locale.

Parameters ​

requested ​

string

Returns ​

Translator<C>


list() ​

> list(items, options?): string

Defined in: i18n/src/i18n.ts:83

Parameters ​

items ​

string[]

options? ​

ListFormatOptions

Returns ​

string


locale() ​

> locale(): string

Defined in: i18n/src/i18n.ts:41

The locale for the current request, validated — an invalid value falls back to defaultLocale.

Returns ​

string


n() ​

> n(value, options?): string

Defined in: i18n/src/i18n.ts:71

Parameters ​

value ​

number

options? ​

NumberFormatOptions

Returns ​

string


relativeTime() ​

> relativeTime(value, unit, options?): string

Defined in: i18n/src/i18n.ts:80

Parameters ​

value ​

number

unit ​

RelativeTimeFormatUnit

options? ​

RelativeTimeFormatOptions

Returns ​

string


t() ​

> t(key, params?): string

Defined in: i18n/src/i18n.ts:68

Parameters ​

key ​

keyof C & string

params? ​

Record<string, unknown>

Returns ​

string

Released under the MIT License.