Intl.DisplayNames
Inoffizielle Beta-Übersetzung
Diese Seite wurde von PageTurner AI übersetzt (Beta). Nicht offiziell vom Projekt unterstützt. Fehler gefunden? Problem melden →
Ein Polyfill für Intl.DisplayNames.
Installation
- npm
- yarn
npm i @formatjs/intl-displaynames
yarn add @formatjs/intl-displaynames
Anforderungen
-
Intl.Localeoder Polyfill.
Funktionen
Vollständige Implementierung der Intl.DisplayNames-Spezifikation.
Verwendung
Über polyfill-fastly.io
Verwenden Sie den polyfill-fastly.io URL Builder, um ein Polyfill-Script-Tag für Intl.DisplayNames zu erstellen. Standardmäßig enthält die generierte URL keine Lokalisierungsdaten. Um Lokalisierungsdaten hinzuzufügen, ergänzen Sie Intl.DisplayNames.~locale.<locale> in Ihrer Feature-Liste. Beispiel:
<!-- 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>
Einfach
import '@formatjs/intl-displaynames/polyfill'
import '@formatjs/intl-displaynames/locale-data/en' // locale-data for en
Dynamischer Import + Funktionserkennung
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}`)
}