Intl.DisplayNames() constructor
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)
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 the Intl page. 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.
- "
language
" - "
region
" - "
script
" - "
currency
"
- "
fallback
-
The fallback to use, the default is "
code
".- "
code
" - "
none
"
- "
Examples
Basic usage
In basic use without specifying a locale, a formatted string in the default locale and with default options is returned.
console.log((new Intl.DisplayNames([], {type: 'language'})).of('US')); // Expected output: 'us'
Specifications
Specification |
---|
ECMAScript Internationalization API Specification (ECMAScript Internationalization API) # sec-intl-displaynames-constructor |
Browser compatibility
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
DisplayNames |
81 |
81 |
86 |
No |
68 |
14.1 |
81 |
81 |
86 |
58 |
14.5 |
13.0 |
See also
© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/DisplayNames