@zerolith/i18n
Import from @zerolith/i18n. Generated from the source; every signature below is what the published types declare.
Functions
parseAcceptLanguage
function parseAcceptLanguage(header: string | null | undefined): LanguageRange[]Parses an Accept-Language header into ranges ordered by quality, dropping those with quality zero.
Source: packages/i18n/src/index.ts:21
negotiateLocale
function negotiateLocale(requested: string | readonly string[] | null | undefined, supported: readonly string[], fallback: string): stringPicks the supported locale that best matches what was requested: an
Accept-Language header, navigator.languages, or one tag. Each range
is tried in order of quality, first as an exact match, then by dropping
subtags from the end as RFC 4647 lookup does, then as the language of a
more specific supported locale, preferring one written in the same
script, so zh-HK finds zh-TW before zh-CN. * and no match at all
give fallback.
Source: packages/i18n/src/index.ts:75
localeDirection
function localeDirection(locale: string): "ltr" | "rtl"The writing direction of a locale, from Intl.Locale where the engine provides it and otherwise from its script, the likely one when the tag names none, as engines decide.
Source: packages/i18n/src/index.ts:122
createLocale
function createLocale(options: LocaleOptions): LocaleStateCreates the locale state for an application. Throws a TypeError when supported is empty or fallback is not one of its locales, since the locale must always be one of them.
Source: packages/i18n/src/index.ts:166
applyLocale
function applyLocale(state: LocaleState, doc?: Document): () => voidKeeps the document's lang and dir attributes in step with the locale; returns the effect's disposer.
Source: packages/i18n/src/index.ts:191
formatters
function formatters(locale: ReadableSignal<string> | string): FormattersCreates formatters over a locale, given as a signal or as a fixed tag. Instances are cached per locale and options.
Source: packages/i18n/src/index.ts:230
Interfaces
LanguageRange
interface LanguageRangeOne entry of an Accept-Language header or of navigator.languages.
readonly range: string: The language tag, or*for any language, as written before any;parameters.readonly quality: number: The entry'sqweight between 0 and 1, rounded to three decimals; 1 when the entry gives none.
Source: packages/i18n/src/index.ts:12
LocaleOptions
interface LocaleOptionsOptions for createLocale.
supported: readonly string[]: The locales the application ships, most preferred first.fallback?: string: The locale used when nothing matches, one ofsupported. Defaults to the first supported one.initial?: string | readonly string[] | null: What to negotiate from at first: anAccept-Languageheader,navigator.languages, or a tag. Defaults to the fallback.
Source: packages/i18n/src/index.ts:142
LocaleState
interface LocaleStateThe current locale as state.
readonly locale: ReadableSignal<string>: The current locale, always one ofsupported.readonly direction: ReadableSignal<"ltr" | "rtl">: The writing direction of the current locale.readonly supported: readonly string[]: A copy of thesupportedoption, in the same order;setnegotiates against it.set(requested: string | readonly string[]): void: Switches locales after negotiating the request againstsupported.
Source: packages/i18n/src/index.ts:153
Formatters
interface FormattersFormatters for the current locale; each reads the locale signal when called, so a computed value or template re-renders on a locale change.
number(value: number, options?: Intl.NumberFormatOptions): string: Formats a number withIntl.NumberFormat.date(value: Date | number, options?: Intl.DateTimeFormatOptions): string: Formats aDate, or a timestamp in milliseconds since the epoch, withIntl.DateTimeFormat.relative(value: number, unit: Intl.RelativeTimeFormatUnit, options?: Intl.RelativeTimeFormatOptions): string: Formats a timevalueunits ofunitaway from now withIntl.RelativeTimeFormat, such asin 2 hours; a negative value lies in the past.list(values: Iterable<string>, options?: Intl.ListFormatOptions): string: Joins strings into a list withIntl.ListFormat, such asa, b, and cin English.plural(value: number, options?: Intl.PluralRulesOptions): Intl.LDMLPluralRule: Selects the plural category of a number withIntl.PluralRules, such asoneorother, for choosing a message variant.
Source: packages/i18n/src/index.ts:201