Zum Hauptinhalt springen

Intl.PluralRules

Inoffizielle Beta-Übersetzung

Diese Seite wurde von PageTurner AI übersetzt (Beta). Nicht offiziell vom Projekt unterstützt. Fehler gefunden? Problem melden →

Ein spezifikationskonformer Polyfill für Intl.PluralRules, vollständig getestet durch die offizielle ECMAScript-Konformitätstest-Suite.

npm Version size

Installation

npm i @formatjs/intl-pluralrules

Anforderungen

Verwendung

Über polyfill-fastly.io

Sie können den polyfill-fastly.io URL Builder verwenden, um ein Polyfill-Script-Tag für Intl.PluralRules zu erstellen. Standardmäßig enthält die erzeugte URL keine Lokalisierungsdaten. Um Lokalisierungsdaten hinzuzufügen, ergänzen Sie Intl.PluralRules.~locale.<locale> in Ihrer Feature-Liste. Beispiel:

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

Einfach

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

React Native

Der Code zur bedingten Polyfill-Erkennung läuft auf Android sehr langsam und kann den App-Start um Sekunden verzögern. Da React Native Hermes verwendet, das Intl.PluralRules nicht unterstützt, importieren Sie stattdessen /polyfill-force für deutlich bessere Leistung:

import '@formatjs/intl-pluralrules/polyfill-force' // instead of /polyfill
import '@formatjs/intl-pluralrules/locale-data/en'

Dynamischer Import + Funktionserkennung

import {shouldPolyfill} from '@formatjs/intl-pluralrules/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-pluralrules/polyfill-force')
await import(`@formatjs/intl-pluralrules/locale-data/${unsupportedLocale}`)
}