Skip to content

@jsvision/ui / I18n

Interface: I18n

Defined in: i18n/dist/types.d.ts:208

Locale-bound translation and formatting service.

Example

ts
import { createI18n } from '@jsvision/i18n';

const i18n = createI18n({ locale: 'nl' });
i18n.t('app.greeting', { defaultMessage: 'Hello' });

Properties

availableLocales

readonly availableLocales: readonly string[]

Defined in: i18n/dist/types.d.ts:214

Sorted catalog locales currently available to lookup.


diagnostics

readonly diagnostics: readonly I18nDiagnostic[]

Defined in: i18n/dist/types.d.ts:216

Deduplicated recoverable diagnostics, bounded to 100 records.


fallbackLocales

readonly fallbackLocales: readonly string[]

Defined in: i18n/dist/types.d.ts:212

Canonical configured fallbacks including final English.


locale

readonly locale: string

Defined in: i18n/dist/types.d.ts:210

Canonical requested locale used for formatting.

Methods

compare()

compare(left, right, options?): number

Defined in: i18n/dist/types.d.ts:249

Compares normalized strings with a locale-bound collator.

Parameters

left

string

First string.

string

Second string.

options?

CollatorOptions

Copied native collation options.

Returns

number

Negative, zero, or positive comparison result.


date()

date(value, options?): string

Defined in: i18n/dist/types.d.ts:240

Formats a valid date or finite epoch milliseconds for the service locale.

Parameters

value

number | Date

Date value to format.

options?

DateTimeFormatOptions

Copied native formatting options.

Returns

string

Locale-formatted date.


has()

has(key, locale?): boolean

Defined in: i18n/dist/types.d.ts:257

Reports whether a key exists in the selected locale's catalog fallback path.

Parameters

key

string

Namespaced message key.

locale?

string

Optional locale override for introspection only.

Returns

boolean

true when a catalog message can be resolved.


number()

number(value, options?): string

Defined in: i18n/dist/types.d.ts:232

Formats a finite number or bigint for the service locale.

Parameters

value

number | bigint

Numeric value to format.

options?

NumberFormatOptions

Copied native formatting options.

Returns

string

Locale-formatted number.


setCatalog()

setCatalog(catalog): void

Defined in: i18n/dist/types.d.ts:264

Atomically replaces the highest-priority runtime overlay for one locale.

Parameters

catalog

unknown

Untrusted catalog input validated before publication.

Returns

void

Throws

An I18nError when the catalog is invalid.


t()

t(key, options?): string

Defined in: i18n/dist/types.d.ts:224

Resolves and evaluates one translated message.

Parameters

key

string

Namespaced message key.

options?

TranslateOptions

Safe parameters and optional English default.

Returns

string

Resolved text, the call-site default, or the key.