Intl.DisplayNames()
constructor creates objects that enables the consistent translation of language, region and script display names.
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
new Intl.DisplayNames([locales[, options]])
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
"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
"lookup"
and
"best fit"
; the default is
"best fit"
. For information about this option, see the
Intl page
.
style
"long"
.
"narrow"
"short"
"long"
type
"language"
.
"language"
"region"
"script"
"currency"
fallback
"code"
.
"code"
"none"
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()).of('US'));
// Expected output: 'us'
| 规范 |
|---|
|
Intl.DisplayNames
The definition of 'the Intl.DisplayNames constructor' in that specification. |
| Desktop | Mobile | Server | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
DisplayNames()
构造函数
|
Chrome 81 | Edge 81 | Firefox No | IE No | Opera 68 | Safari No | WebView Android 81 | Chrome Android 81 | Firefox Android No | Opera Android 58 | Safari iOS No | Samsung Internet Android No | nodejs 14.0.0 |
完整支持
不支持
Intl
Collator
DateTimeFormat
ListFormat
NumberFormat
PluralRules
RelativeTimeFormat
Object
Object.prototype.__defineGetter__()
Object.prototype.__defineSetter__()
Object.prototype.__lookupGetter__()
Object.prototype.__lookupSetter__()
Object.prototype.hasOwnProperty()
Object.prototype.isPrototypeOf()
Object.prototype.propertyIsEnumerable()
Object.prototype.toLocaleString()
Object.prototype.toSource()
Object.prototype.toString()
Object.prototype.valueOf()
Object.setPrototypeOf()