Lean-Intl is a lean polyfill for Intl-APIs for browsers which are not yet supporting this API. It's a modern fork of Intl.js with up-to-data data, adjusted to modern development workflows and tooling requirements.
Lean-Intl is a lean polyfill for Intl
-APIs for browsers which are not yet supporting this API. It’s a
modern fork of Intl.js for modern development and tooling requirements.
In December 2012, ECMA International published the first edition of Standard ECMA-402,
better known as the ECMAScript Internationalization API. This specification provides
the framework to bring long overdue localization methods to ECMAScript implementations.
All modern browsers and NodeJS (except Safari <= 10 and IE <= 10) have implemented this API. Lean-Intl
fills the void of availability for this API. It will provide the framework as described by the specification, so that developers can take advantage of the native API in environments that support it, or Lean-Intl
for legacy or unsupported environments.
See browser support on the official CanIUse Database for details
Intl.js
is not maintained. It has failing tests. This one is maintained - but nothing more. It does not receive much love other than data updates and dependency updates.Intl.js
uses version 29.0.0
, this one uses 35.0.0
. That’s a major difference of about three years.IntlPolyfill.__addLocaleData()
) and JS files (they register automatically + they load the polyfill before as well).Lean Intl is meanted to be used by module bundlers. We are not offering any pre-built browser-ready
scripts anymore. In todays landscape it’s much better to rely on some kind of bundling for delivering
your frontend goods.
brew install node --with-full-icu
)For server side just import the whole package and assign it to the global Intl
object:
import Intl from 'intl'
global.Intl = Intl
On the client side decide whether you want to use JS and JSON data packages. JS has the benefit of auto-registration, JSON is slightly smaller (no imports, no registration code) but requires manual work.
import 'lean-intl/locale-data/js/de' // German data
import 'lean-intl/locale-data/js/en' // English data
import Intl from 'lean-intl'
import esData from 'lean-intl/locale-data/json/es.json'
import frData from 'lean-intl/locale-data/json/fr.json'
global.Intl = global.IntlPolyfill
Intl.__addLocaleData(esData)
Intl.__addLocaleData(frData)
import Intl from 'lean-intl'
global.Intl = global.IntlPolyfill
const locale = getBrowserLocale() // requires implementation
const localeData = await import(`lean-intl/locale-data/json/${locale}.json`)
Intl.__addLocaleData(localeData)
Current progress is as follows:
Intl.NumberFormat
Intl.NumberFormat
constructor (11.1)Intl.NumberFormat
Constructor (11.2)Intl.NumberFormat
Prototype Object (11.3)Intl.DateTimeFormat
Intl.DateTimeFormat
constructor (12.1)Intl.DateTimeFormat
Constructor (12.2)Intl.DateTimeFormat
Prototype Object (12.3)Number
Prototype Object (13.2)Date
prototype object (13.3)BestFitSupportedLocales
internal functionIntl.Collator
) (see below)String
prototype objectA few of the implemented functions may currently be non-conforming and/or incomplete.
Most of those functions have comments marked as ‘TODO’ in the source code.
The test suite is run with Intl.Collator tests removed, and the Collator
constructor removed from most other tests in the suite. Also some parts of
tests that cannot be passed by a JavaScript implementation have been disabled,
as well as a small part of the same tests that fail due to (this bug in v8)[https://code.google.com/p/v8/issues/detail?id=2694].
Providing an Intl.Collator
implementation is no longer a goal of this project. There
are several reasons, including:
Lean Intl
is designed to be compatible with ECMAScript 3.1 environments in order to
follow the specification as closely as possible. However, some consideration is given
to legacy (ES3) environments, and the goal of this project is to at least provide a
working, albeit non-compliant implementation where ES5 methods are unavailable.
A subset of the tests in the test suite are run in IE 8. Tests that are not passable
are skipped, but these tests are mostly about ensuring built-in function behavior.
Lean Intl
uses the Unicode CLDR locale data, as recommended by the specification. The main Lean Intl
file contains no locale data itself. The
data should be loaded as JSON and passed into a JavaScript object using the
IntlPolyfill.__addLocaleData()
method. Alternatively there is a JS data file available as well
for each locale which directly executes that code.
Contents of the locale-data
directory are a modified form of the Unicode CLDR
data found at http://www.unicode.org/cldr/.
Lean Intl
attempts to cache and restore static RegExp properties before executing any
regular expressions in order to comply with ECMA-402. This process is imperfect,
and some situations are not supported. This behavior is not strictly necessary, and is only
required if the app depends on RegExp static properties not changing (which is highly
unlikely). To disable this functionality, invoke Intl.__disableRegExpRestore()
.
This software is licensed under the MIT license. See the LICENSE.txt
file
accompanying this software for terms of use.
Copyright 2013 Andy Earnshaw
Copyright 2016-2019 Sebastian Software GmbH