Aller au contenu principal

Intl.DisplayNames

Traduction Bêta Non Officielle

Cette page a été traduite par PageTurner AI (bêta). Non approuvée officiellement par le projet. Vous avez trouvé une erreur ? Signaler un problème →

Un polyfill pour Intl.DisplayNames.

npm Version size

Installation

npm i @formatjs/intl-displaynames

Prérequis

Fonctionnalités

L'intégralité de la proposition intl-displaynames.

Utilisation

Via polyfill-fastly.io

Utilisez le Générateur d'URL polyfill-fastly.io pour créer une balise script de polyfill pour Intl.DisplayNames. Par défaut, l'URL générée ne contient aucune donnée de locale. Pour ajouter des données de locale, ajoutez Intl.DisplayNames.~locale.<locale> à votre liste de fonctionnalités. Par exemple :

<!-- 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>

Exemple simple

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

Import dynamique + détection de capacités

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}`)
}