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

I am migrating from Globalize.js V0.0.1 to V1.0.0. In V0.0.1, you could access the downloaded culture data, as you can see below. How can I access data with the 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 in advance!

+2
javascript javascript-globalize
source share
1 answer

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

Access to the CLDR can be obtained via https://github.com/unicode-cldr/ , or you can install it locally with:

 $ npm install cldr-data 

Globalization, under the hoods, traverses CLDR data using Cldrjs. You can use it yourself regardless of globalization to move 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 your 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 information at https://github.com/rxaviers/cldrjs and https://github.com/jquery/globalize

Just let me know on any issue.

+1
source share

All Articles