Is there an i18n (Intl) shim for JavaScript?

别等时光非礼了梦想. 提交于 2019-12-03 12:06:20

问题


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


回答1:


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.




回答2:


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




回答3:


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

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