| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/of | [Back] [Original] |
Get to know MDN better
const regionNamesInEnglish = new Intl.DisplayNames(["en"], { type: "region" });
const regionNamesInTraditionalChinese = new Intl.DisplayNames(["zh-Hant"], {
type: "region",
});
console.log(regionNamesInEnglish.of("US"));
// : "United States"
console.log(regionNamesInTraditionalChinese.of("US"));
// : ""
of(code)
code code type
code 2 ISO 3166 3 M49 unicode_region_subtag "us" "US" code ISO-15924 4 unicode_script_subtag code unicode_language_id code 3 ISO 4217 3 code "era""year""quarter""month""weekOfYear""weekday""day""dayPeriod""hour""minute""second""timeZoneName" code Unicode type fallback "none" undefined
:
fallback code fallback
RangeError type code
const regionNames = new Intl.DisplayNames("en", { type: "region" });
regionNames.of("419"); // "Latin America"
const languageNames = new Intl.DisplayNames("en", { type: "language" });
languageNames.of("fr"); // "French"
const currencyNames = new Intl.DisplayNames("en", { type: "currency" });
currencyNames.of("EUR"); // "Euro"
const languageNamesStandard = new Intl.DisplayNames("fr", {
type: "language",
languageDisplay: "standard",
});
languageNamesStandard.of("fr-CA"); // "franais (Canada)"
const languageNamesDialect = new Intl.DisplayNames("fr", {
type: "language",
languageDisplay: "dialect",
});
languageNamesDialect.of("fr-CA"); // "franais canadien"
Intl.DisplayNames fallback: "code" of() code fallback "none" undefined
console.log(
new Intl.DisplayNames("en", { type: "region", fallback: "code" }).of("ZL"),
); // "ZL"
console.log(
new Intl.DisplayNames("en", { type: "region", fallback: "none" }).of("ZL"),
); // undefined
code type "region" code unicode_region_subtag 2 3 RangeError
console.log(
new Intl.DisplayNames("en", { type: "region", fallback: "code" }).of("ZLC"),
); // throws RangeError: invalid value "ZLC" for option region
| ECMAScript 2027 Internationalization API Specification # sec-Intl.DisplayNames.prototype.of |
| Web Proxy Viewer | New URL | Original Page |