Intl.RelativeTimeFormat
Diese Seite wurde von PageTurner AI übersetzt (Beta). Nicht offiziell vom Projekt unterstützt. Fehler gefunden? Problem melden →
Ein spezifikationskonformes Polyfill für Intl.RelativeTimeFormat, vollständig getestet durch die offizielle ECMAScript-Konformitätstest-Suite
Installation
- npm
- yarn
npm i @formatjs/intl-relativetimeformat
yarn add @formatjs/intl-relativetimeformat
Anforderungen
Dieses Paket erfordert folgende Funktionen:
-
Intl.Localeoder Polyfill. -
Intl.PluralRulesoder Polyfill -
Wenn Sie
formatToPartsbenötigen und IE11 oder Node 10 unterstützen müssen, benötigen Sie ein Polyfill von@formatjs/intl-numberformat
Verwendung
Über polyfill-fastly.io
Sie können den polyfill-fastly.io URL Builder verwenden, um ein Polyfill-Script-Tag für Intl.RelativeTimeFormat zu erstellen. Standardmäßig enthält die generierte URL keine Lokalisierungsdaten. Um Lokalisierungsdaten hinzuzufügen, ergänzen Sie Intl.RelativeTimeFormat.~locale.<locale> in Ihrer Feature-Liste. Beispiel:
<!-- Polyfill Intl.RelativeTimeFormat, its dependencies & `en` locale data -->
<script src="https://polyfill-fastly.io/v3/polyfill.min.js?features=Intl.RelativeTimeFormat,Intl.RelativeTimeFormat.~locale.en"></script>
Einfach
import '@formatjs/intl-relativetimeformat/polyfill'
import '@formatjs/intl-relativetimeformat/locale-data/en' // locale-data for en
Dynamischer Import + Funktionserkennung
import {shouldPolyfill} from '@formatjs/intl-relativetimeformat/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-relativetimeformat/polyfill-force')
await import(
`@formatjs/intl-relativetimeformat/locale-data/${unsupportedLocale}`
)
}
Tests
Diese Bibliothek ist vollständig test262-konform.