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.)
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
.
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
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).
来源:https://stackoverflow.com/questions/14755521/is-there-an-i18n-intl-shim-for-javascript