Skip to content

Intl (JavaScript)

This page describes functionality behind the Intl namespace object in JavaScript. For more information consult the MDN web docs.

Intl.DisplayNames

This function can be used to display the name of a language, region, or script.

For example, to get the display name for English (as spoken in the US), the Intl.DisplayNames object can be used to generate the name "American English".

For more information consult the MDN web docs.

Locale expectations

In English, names of languages are capitalized. But this rule is not applicable to all languages.

People unfamiliar with French will be surprised to know that in French the language is not capitalized (unless it's the beginning of the sentence). So if someone is expecting to use this in generating a UI for selecting different languages, they'll discover that the function will translate "English" in French as "anglais". This means someone will have to transform the first letter in the text to uppercase for it to look right in the UI.

Technical consistency

The MDN docs claim it enables "consistent translation", but this is a lie! There are some cases where the results are not the same. On some browsers:

  • the display name for fr-US may be "French (US)" or "French (United States)",
  • the display name for zh-CN may be "Chinese (China)" or "Chinese (China mainland)"

Behaviour across platforms

Below is a list of language names for various language-tags in English.

The final row in the table is what your browser resolves the display name for a language to.

let languageNames = new Intl.DisplayNames(["en"], { type: "language" });
const displayName = languageNames.of(languageTag);
Language Tag en en-US en-CA en-GB en-IE en-FR fr fr-US fr-CA fr-GB fr-IE fr-FR zh-CN zh-TW
Safari on macOS/iOS English American English Canadian English British English English (Ireland) English (France) French French (US) Canadian French French (UK) French (Ireland) French (France) Chinese (China mainland) Chinese (Taiwan)
Firefox on Ubuntu English American English Canadian English British English English (Ireland) English (France) French French (United States) Canadian French French (United Kingdom) French (Ireland) French (France) Chinese (China) Chinese (Taiwan)
Chrome on Android English American English Canadian English British English English (Ireland) English (France) French French (United States) Canadian French French (United Kingdom) French (Ireland) French (France) Chinese (China) Chinese (Taiwan)
Your Browser - - - - - - - - - - - - - -