Npm's cldr-data
Npm module for Unicode CLDR JSON data.
Goal
- Allow i18n libraries to define CLDR data as versioned "peer" dependency.
- Provide tools to assist (in other words, ease the pain) on fetching the data.
Bonus goals
Usage
On the package.json
of your i18n library, define its CLDR data dependency.
compatible with.
"peerDependencies": {
"cldr-data": ">=25"
}
On your library, access CLDR JSON data using require("cldr-data")
.
cldr = require("cldr-data");
function Pluralize(locale) {
var plurals = cldr("supplemental/plurals");
var language = extractLanguageFrom(locale);
pluralForm = doAwesomeStuffWith(
plurals.supplemental["plurals-type-cardinal"][language]
);
return pluralForm;
}
For your convinience, use cldr-data in conjunction with cldr.js. You can
find more details switching to the Foo Number Format Library Example or
Application Example branches.
Locale coverage
By default, the locale coverage installed is core
, which Unicode defines as
the top tier languages and is equivalent to the json.zip
content. If you need
full locale coverage, use CLDR_COVERAGE
environment variable to modify the
installation behavior. For example:
$ CLDR_COVERAGE=full npm install
License
MIT © Rafael Xavier de Souza