CLDR.General
bundle
Returns a reference to the Bundle for this CLDR instance.
Syntax
bundle(): Bundle
Example
for (const locale of ['en', 'fr', 'ja', 'ar']) {
const cldr = framework.get(locale);
const b = cldr.General.bundle();
log(`${b.id()} ${b.language()} ${b.region()}`);
}
en-Latn-US en US fr-Latn-FR fr FR ja-Jpan-JP ja JP ar-Arab-EG ar EG
characterOrder
Returns the character order for the current locale.
Syntax
characterOrder(): CharacterOrderType
Return values
"ltr"- Left to right
"rtl"- Right to left
lineOrder
Returns the line order for the current locale.
Syntax
lineOrder(): LineOrderType
Return values
"ttb"- Top to bottom
"btt"- Bottom to top
locale
Returns the Locale for this CLDR instance.
Syntax
locale(): Locale
Example
for (const locale of ['en', 'fr', 'ja', 'ar']) {
const cldr = framework.get(locale);
const { tag } = cldr.General.locale();
log(tag.expanded());
}
en-Latn-US fr-Latn-FR ja-Jpan-JP ar-Arab-EG
formatList
Format a list of items, with a given list type, returning a string.
Syntax
formatList(items, type?): string
Parameters
items: string[]- Items to join together into a list
type?: ListPatternType- Type of list to format
Example
const cldr = framework.get('en');
const items = ['one', 'two', 'three', 'four', 'five'];
log(cldr.General.formatList(items.slice(0, 2), 'and'));
log(cldr.General.formatList(items, 'or'));
one and two one, two, three, four, or five
formatListToParts
Format a list of items, with a given list type, returning an array of parts.
Syntax
formatList(items, type?): Part[]
Parameters
items: string[]- Items to join together into a list
type?: ListPatternType- Type of list to format
Example
const cldr = framework.get('en');
const items = ['one', 'two', 'three', 'four', 'five'];
log(cldr.General.formatListToParts(items.slice(0, 2), 'and'));
log(cldr.General.formatListToParts(items, 'or'));
[
{ type: 'item', value: 'one' },
{ type: 'literal', value: ' and ' },
{ type: 'item', value: 'two' }
]
[
{ type: 'item', value: 'one' },
{ type: 'literal', value: ', ' },
{ type: 'item', value: 'two' },
{ type: 'literal', value: ', ' },
{ type: 'item', value: 'three' },
{ type: 'literal', value: ', ' },
{ type: 'item', value: 'four' },
{ type: 'literal', value: ', or ' },
{ type: 'item', value: 'five' }
]
getLanguageDisplayName
Return the display name for a given language code.
Syntax
getLanguageDisplayName(code, options?): string
Parameters
code: string | LanguageTag- Valid ISO 639 language identifier, a LanguageTag instance or parseable string
options?: DisplayNameOptions- Options for selecting the display name
Example
const en = framework.get('en');
const ids = ['fr', 'ko', 'en', 'und-US', 'en-GB', 'zh-CN', 'zh-TW'];
for (const id of ids) {
log(en.General.getLanguageDisplayName(id));
}
French Korean English American English British English Simplified Chinese Traditional Chinese
You can also pass in a LanguageTag instance.
const en = framework.get('en');
for (const id of ['en', 'und', 'und-GB']) {
const tag = en.General.parseLanguageTag(id);
log(en.General.getLanguageDisplayName(tag));
}
English Unknown language British English
getRegionDisplayName
Return the name of a given region.
Syntax
getRegionDisplayName(code, options?): string
Parameters
code: string | LanguageTag- Valid ISO 3166-1 alpha-2 or UN M.49 region identifier, a LanguageTag instance or parseable string
options?: DisplayNameOptions- Options for selecting the display name
Example
const en = framework.get('en');
const fr = framework.get('fr');
const ids: string[] = ['US', 'CA', 'BE', 'ZA', 'ZZ', 'en-ZZ'];
for (const id of ids) {
const a = en.General.getRegionDisplayName(id);
const b = fr.General.getRegionDisplayName(id);
log(`en=${a} fr=${b}`);
}
en=United States fr=États-Unis en=Canada fr=Canada en=Belgium fr=Belgique en=South Africa fr=Afrique du Sud en=Unknown Region fr=région indéterminée en=United States fr=États-Unis
getScriptDisplayName
Return the name of a given script.
Syntax
getScriptDisplayName(code, options?): string
Parameters
code: string | LanguageTag- Valid ISO 15924 script identifier, a LanguageTag instance or parseable string
options?: DisplayNameOptions- Options for selecting the display name
Example
const en = framework.get('en');
const de = framework.get('de');
const ids: string[] = ['Latn', 'Egyp', 'Cyrl', 'Zzzz', 'en', 'zh-CN', 'zh-TW'];
for (const id of ids) {
const a = en.General.getScriptDisplayName(id);
const b = de.General.getScriptDisplayName(id);
log(`en=${a} de=${b}`);
}
en=Latin de=Lateinisch en=Egyptian hieroglyphs de=Ägyptische Hieroglyphen en=Cyrillic de=Kyrillisch en=Unknown Script de=Unbekannte Schrift en=Latin de=Lateinisch en=Simplified de=Vereinfacht en=Traditional de=Traditionell
measurementSystem
Syntax
measurementSystem(category?: MeasurementCategory): MeasurementSystem
Parameters
category?: MeasurementCategory- Optional category (ex: temperature has special handling for certain regions)
Return values
A MeasurementSystem value
Example
const cldr = framework.get('es-PR');
log(cldr.General.measurementSystem());
log(cldr.General.measurementSystem('temperature'));
metric us
messageFormatter
Returns an extensible message formatter for the current locale. See MessageFormatter
Syntax
messageFormatter(options?: MessageFormatterOptions): MessageFormatter
Example
const formatters = {
emphatic: (args: MessageArg[], options: string[]) => args[0].toUpperCase() + '!'
};
const cldr = framework.get('pt-PT');
const formatter = cldr.General.messageFormatter({ formatters });
log(formatter.format('Hi, {thing emphatic}', [], { thing: 'computer' }));
Hi, COMPUTER!
parseLanguageTag
Parses a language tag and canonicalizes its fields, returning a LanguageTag object.
Syntax
parseLanguageTag(tag: string): LanguageTag
Parameters
tag: string- String to parse into a LanguageTag object
Example
const cldr = framework.get('en');
log(cldr.General.parseLanguageTag('fr-AU').expanded());
log(cldr.General.parseLanguageTag('en').expanded());
fr-Zzzz-AU en-Zzzz-ZZ
resolveLocale
Parses and resolves a locale identifer or language tag into a Locale object.
Resolution involves:
- Replace language and region aliases
- Remap grandfathered tags
- Add likely subtags
Syntax
resolveLocale(tag): Locale
Parameters
tag: string- String to parse into a Locale object
Example
const cldr = framework.get('en');
const ids = [
'en_CA',
'ko',
'und-Cyrl',
'fr-u-ca-persian-u-nu-mathmono',
'und-CN'
];
for (const id of ids) {
const { tag } = cldr.General.resolveLocale(id);
log(`${tag.language()} ${tag.script()} ${tag.region()}`);
}
en Latn CA ko Kore KR ru Cyrl RU fr Latn FR zh Hans CN