Is there an i18n (Intl) shim for JavaScript?

十年热恋 提交于 2019-12-03 01:42:31
Andy E

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.

Jaco Koster

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).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!