asDisplayString
function
Brands a string as a presentation-plane value.
| Package | @formscript/i18n |
|---|---|
| Specification | 12, 12.2 |
| Depends on | nothing — it is a leaf |
@formscript/i18nInternationalisation: the text catalogue, locale resolution and ICU message formatting, per §12 of the specification.
import { Catalogue } from '@formscript/i18n';
const catalogue = new Catalogue({
'greeting': { default: 'Hello', fr: 'Bonjour' },
});
catalogue.resolve('greeting', 'fr-GB', { name: 'Ada' });
Resolution follows the fallback chain of §12.2: the exact locale, then the language, then the default. A key that resolves nowhere yields the key itself, so a missing translation is visible rather than silent.
The parser is a recursive descent over the ICU MessageFormat grammar, so a
malformed message is reported with a position rather than throwing.
parseMessage('Hello {name}, you have {count, plural, =0 {no messages} one {# message} other {# messages}}.');
The plural categories follow CLDR 46, for 27 locales and 40 ordinal
locales. Languages with three or six forms — Polish, Russian, Arabic, Welsh —
are handled by the rules, not by a hardcoded one/other table.
The fallback is the host platform's CLDR data, never a guess.
26 exported symbols.
asDisplayString
function
Brands a string as a presentation-plane value.
CatalogueEntry
interface
A catalogue entry: one string, or a map of locale tag to string.
DEFAULT_LOCALE_KEY
const
The reserved catalogue key holding the default-locale text (Spec-4.37).
DisplayString
type
A presentation-plane value: a string at runtime, a distinct type (Spec-5.1).
formatIcuMessage
function
Formats an ICU message, selecting plurals with the locale's CLDR rules.
IcuArgs
interface
Named arguments supplied to a message.
IcuError
class
The error raised for a malformed message.
IcuFormatOptions
interface
Options that control how a message is formatted.
IcuNode
type
A parsed message node.
IcuValue
type
A value that can be substituted into a message.
isDisplayString
function
Narrows a value to a presentation-plane string; a `display` is a string at runtime.
isSupportedPluralLocale
re-exportlanguageOf
function
The language-only form of a locale tag: `fr-CA` becomes `fr`.
Locale
type
A BCP-47 language tag.
normalizeLocale
function
Canonicalises a locale tag: `fr_ca` becomes `fr-CA`.
ordinalCategory
re-exportparseIcuMessage
function
Parses an ICU MessageFormat message into its node tree.
PLURAL_FALLBACK_LOCALE
re-exportpluralCategory
re-exportPluralCategory
type
CLDR plural categories, in CLDR evaluation order.
pluralOperands
re-exportPluralOperands
interface
The CLDR plural operands derived from a number.
resolveLocaleChain
function
The locale fallback chain of Spec-12.4: exact locale, language-only form, default locale.
SUPPORTED_ORDINAL_LOCALES
re-exportSUPPORTED_PLURAL_LOCALES
re-exportTextCatalogue
class
The catalogue of user-facing text of a document.