How to access culture data in globalize.js V1.0.0

我与影子孤独终老i 提交于 2019-12-11 04:31:27

问题


I am migrating from Globalize.js V0.0.1 to V1.0.0. In V0.0.1 it was possible to access the loaded culture data as you can see below. How can I access the data with current version 1.0.0.

var culture = Globalize.culture("en-US");
culture.calendar.months.names; // returns: ["January", "February", "March", ...
culture.calendar.days.names;  // returns: ["Sunday", "Monday", "Tuesday", ... 

Thank you very much in advance!


回答1:


In Globalize 0.x, the i18n content was mixed/embedded into the library. Now in Globalize 1.x, we use external CLDR.

CLDR can be accessed via https://github.com/unicode-cldr/, or you can get it installed locally with:

$ npm install cldr-data

Globalize, under the hoods, traverse CLDR data using Cldrjs. You can use it yourself independently of Globalize to traverse CLDR data, for example:

$ npm install cldr-data cldrjs
$ node
> var Cldr = require("cldrjs");
> Cldr.load(require("cldr-data").entireSupplemental());
> Cldr.load(require("cldr-data").entireMainFor("en"));
> 
> var en = new Cldr("en");
> en.main("dates/calendars/gregorian/months/format/wide/1");
'January'
>
> // Note the "{region}" fragment is automatically substituted by the instance's
> // region subtag. See `en.attributes` for all of those variables.
> en.supplemental("currencyData/region/{region}");
[ { USN: { _tender: 'false' } },
  { USS: { _to: '2014-03-01', _tender: 'false' } },
  { USD: { _from: '1792-01-01' } } ]

If you are already using Globalize, you can access this data using its own Cldrjs instance (for convenience):

$ npm install globalize cldr-data
$ node
> var Globalize = require("Globalize");
> Globalize.load(require("cldr-data").entireSupplemental());
> Globalize.load(require("cldr-data").entireMainFor("en"));
> 
> var en = new Globalize("en");
> en.cldr.main("dates/calendars/gregorian/months/format/wide/1");
'January'

More info at https://github.com/rxaviers/cldrjs and https://github.com/jquery/globalize

Just let me know on any question.



来源:https://stackoverflow.com/questions/32142529/how-to-access-culture-data-in-globalize-js-v1-0-0

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