Skip to main content

Intl.DisplayNames

A polyfill for Intl.DisplayNames.

npm Version size

Installation

npm i @formatjs/intl-displaynames

Requirements

Features

Everything in intl-displaynames proposal.

Usage

Via polyfill-fastly.io

You can use polyfill-fastly.io URL Builder to create a polyfill script tag for Intl.DisplayNames. By default the created URL does not come with any locale data. In order to add locale data, append Intl.DisplayNames.~locale.<locale> to your list of features. For example:

<!-- Polyfill Intl.DisplayNames, its dependencies & `en` locale data -->
<script src="https://polyfill-fastly.io/v3/polyfill.min.js?features=Intl.DisplayNames,Intl.DisplayNames.~locale.en"></script>

Simple

import '@formatjs/intl-displaynames/polyfill'
import '@formatjs/intl-displaynames/locale-data/en' // locale-data for en

Dynamic import + capability detection

import {shouldPolyfill} from '@formatjs/intl-displaynames/should-polyfill'
async function polyfill(locale: string) {
const unsupportedLocale = shouldPolyfill(locale)
// This locale is supported
if (!unsupportedLocale) {
return
}
// Load the polyfill 1st BEFORE loading data
await import('@formatjs/intl-displaynames/polyfill-force')
await import(`@formatjs/intl-displaynames/locale-data/${locale}`)
}