The Intl.DisplayNames() constructor creates Intl.DisplayNames objects that enable the consistent translation of language, region and script display names.
Syntax
new Intl.DisplayNames(locales, options)
Note: Intl.DisplayNames() can only be constructed with new. Attempting to call it without new throws a TypeError.
Parameters
locales
A string with a BCP 47 language tag, or an array of such strings. For the general form and interpretation of the locales argument, see Locale identification and negotiation. The following Unicode extension key is allowed:
nu
The numbering system to be used. Possible values include: "arab", "arabext", "bali", "beng", "deva", "fullwide", "gujr", "guru", "hanidec", "khmr", "knda", "laoo", "latn", "limb", "mlym", "mong", "mymr", "orya", "tamldec", "telu", "thai", "tibt".
options
An object with some or all of the following properties:
localeMatcher
The locale matching algorithm to use. Possible values are "lookup" and "best fit"; the default is "best fit". For information about this option, see the Intl page.
style
The formatting style to use, the default is "long".
"narrow""short""long"
type
The type to use.
"calendar""currency""dateTimeField""language""region""script"
languageDisplay
The languageDisplay it’s only usable along with type language, defaults to dialect.
"dialect""standard"
fallback
The fallback to use, the default is "code".
"code""none"
const regionNamesInEnglish = new Intl.DisplayNames([‘en’], { type: ‘region’ });
const regionNamesInTraditionalChinese = new Intl.DisplayNames([‘zh-Hant’], { type: ‘region’ });
console.log(regionNamesInEnglish.of(‘US’));
// Expected output: “United States”
console.log(regionNamesInTraditionalChinese.of(‘US’));
// Expected output: “美國”