19

I am looking for a shim for the ECMAScript Internationalization API. Does anyone know of such a project? (Even if it's still currently a work-in-progress.)

hippietrail
  • 15,848
  • 18
  • 99
  • 158
Nathan Wall
  • 10,530
  • 4
  • 24
  • 47
  • 1
    Maybe ask Norbert Lindenberg directly, who's the editor of that spec – kangax Feb 08 '13 at 17:07
  • Why not go with ISO standards and forget about all the traditional ambiguous dates format my grandma uses? (ISO dates, ISO currency codes, etc.). – oxygen Feb 13 '13 at 22:49
  • Great to know, @AndyE! Keep up the work! I'll be following the progress. – Nathan Wall May 07 '13 at 14:31
  • @NathanWall: The polyfill I wrote now supports `DateTimeFormat` and `NumberFormat`, and is available as a published NPM package. Therefore, I decided it was time to actually provide an answer here. ;-) – Andy E Dec 10 '13 at 10:47

4 Answers4

16

Yes, there's a polyfill for ECMA-402 (aka ECMA Internationalization API Specification) available at https://github.com/andyearnshaw/Intl.js.

For use in Node.js applications, you can install with NPM:

npm install intl

It's also available as a Bower component for the front-end:

bower install intl

There's support for NumberFormat and DateTimeFormat, but no support for Collator. Currently, for client-side browser environments, you need to add the locale data using a separate function. See the README.md file for details.

Disclaimer: @AndyE is the author of Intl.js.

lexicore
  • 42,748
  • 17
  • 132
  • 221
Andy E
  • 338,112
  • 86
  • 474
  • 445
  • Is Collator coming? That's the most interesting bit for me. – hippietrail Apr 04 '15 at 03:28
  • 1
    @hippietrail probably not. I investigated adding Collator early on in development and it would require large downloads to the user's browser for the [DUCET](http://en.m.wikipedia.org/wiki/Unicode_collation_algorithm) and language files. I suspect this would put most people off and the trouble wouldn't be worth it in the end. – Andy E Apr 04 '15 at 11:48
  • This is a pretty serious gap in something that calls itself a polyfill for Intl. You might also expect people to be put off by the fact that no support for collation is included at all. Collation seems to be the awkward stepchild of Intl, due to the problems you describe (which are certainly reasonable). –  Dec 06 '17 at 15:36
  • I agree; we're in 2023 now and I'm just facing this issue. For me it is less about `Intl.Collator` itself as it is that `String.prototype.localeCompare` uses `Intl.Collator` under the hood, so we run into collation issues when sorting lists of names in unsupported locales. Fortunately the count of unsupported locales is very small these days. – cvkline Feb 06 '23 at 19:53
1

This SO-question gives some frameworks for i18n-support in javascript. https://stackoverflow.com/questions/9640630/javascript-i18n-internationalization-frameworks-libraries-for-client-side-use

Community
  • 1
  • 1
Jaco Koster
  • 497
  • 3
  • 14
  • 2
    Thank you, but I am looking specifically for one which is a direct shim of the [ECMAScript Internationalization API](http://www.ecma-international.org/ecma-402/1.0/). – Nathan Wall Feb 11 '13 at 18:10
1

I assume you know that "Google Chrome version 24, currently in beta, implements the API with Collator, NumberFormat, and DateTimeFormat objects as described above." (see here). Any shim would either be huge and/or incomplete in terms of locale coverage--do you really want to implement Kannada numbers (that's the language they speak here in Bangalore)?

My suggestion would be to roll your own slimmed-down shim with the parts you need, picking and choosing from other libraries that do similar things as needed. For instance, you might want date/time formatting, but not sorting (which is complicated).

0

Just found this old question and since the ECMA-402 implementation is not available in all browsers I found the polyfills of formatjs.io to be useful in case you need to support browsers like Safari or IE.

Akora
  • 756
  • 7
  • 22