Back to Formatjs

Intl Getcanonicallocales

docs/src/docs/polyfills/intl-getcanonicallocales.mdx

4.5.01.8 KB
Original Source

A spec-compliant polyfill/ponyfill for Intl.getCanonicalLocales tested by the official ECMAScript Conformance test suite

Installation

<Tabs groupId="npm" defaultValue="npm" values={[ {label: 'npm', value: 'npm'}, {label: 'yarn', value: 'yarn'}, {label: 'pnpm', value: 'pnpm'}, ]}> <TabItem value="npm">

sh
npm i @formatjs/intl-getcanonicallocales
</TabItem> <TabItem value="yarn">
sh
yarn add @formatjs/intl-getcanonicallocales
</TabItem> <TabItem value="pnpm">
sh
pnpm add @formatjs/intl-getcanonicallocales
</TabItem> </Tabs>

Usage

Via polyfill-fastly.io

You can use polyfill-fastly.io URL Builder to create a polyfill script tag for Intl.GetCanonicalLocales. For example:

html
<!-- Polyfill Intl.GetCanonicalLocales & its dependencies -->
<script src="https://polyfill-fastly.io/v3/polyfill.min.js?features=Intl.GetCanonicalLocales"></script>

Simple

tsx
import '@formatjs/intl-getcanonicallocales/polyfill.js'

Dynamic import + capability detection

tsx
async function polyfill() {
  // This platform already supports Intl.getCanonicalLocales
  if (shouldPolyfill()) {
    await import('@formatjs/intl-getcanonicallocales/polyfill.js')
  }
  // Alternatively, force the polyfill regardless of support
  await import('@formatjs/intl-getcanonicallocales/polyfill-force.js')
}

Tests

This library is test262-compliant.