rxaviers / cldr-data-npm

Npm module for Unicode CLDR JSON data
MIT License
42 stars 28 forks source link

Filter available languages #60

Open lmaillet opened 6 years ago

lmaillet commented 6 years ago

Hi, I'm using cldr-js and cldr-data-npm. It feet's exactly what I need, but currently my app only needs 3 languages (en, fr and ja). Is it possible while packaging my app (I'm using webpack) to filter the included languages ? Or while using cldr-data-npm, to only install needed languages ?

rxaviers commented 6 years ago

Yes, you can include each file explicitly like cldr-data/main/en/numbers.json, but that's a bit tedious. If you're using globalize, you can use globalize webpack plugin.

We should update README.md to reflect this info. Do you want to help?

lmaillet commented 6 years ago

Thank you for your answer.

No, I don't use globalize, because I only need translation for timezones. Here is an extract of my code.

import Cldr from 'cldrjs';
import cldrData from 'cldr-data';
...
Cldr.load(cldrData('supplemental/likelySubtags'));
Cldr.load(cldrData(`main/${lang}/timeZoneNames`));
const cldr = new Cldr(lang);
const translatedTimeZones = cldr.main('dates/timeZoneNames/zone');

Sorry, but where must I explicitly include main/en/timeZoneNames, main/fr/timeZoneNames and main/ja/timeZoneNames ?

Yes, I can help update README.md as soon as I understand how it works ;-)

rxaviers commented 6 years ago

OK. You can't use import cldrData from 'cldr-data' in webpack because it goes crazy --- and webpack is correct in doing so, it's a static compiler. You need to import things explicitly, i.e:

- import cldrData from 'cldr-data';
+ import likelySubtags from 'cldr-data/supplemental/likelySubtags';
+ import enTimeZoneNames from 'cldr-data/main/en/timeZoneNames`;
+ // and so on for other locales...
...
- Cldr.load(cldrData('supplemental/likelySubtags'));
- Cldr.load(cldrData(`main/${lang}/timeZoneNames`));
+ Cldr.load(likelySubtags);
+ Cldr.load(enTimeZoneNames);
+ // and so on for other locales...
lmaillet commented 6 years ago

Works great, you're a hero !

rxaviers commented 6 years ago

Excellent, let's try to help to clarify this to people having same issues in our README. :) Thanks

mummybot commented 6 years ago

Hi Rxaviers,

We are having a related issue to the original request, but it is at install time rather than run or compile time:

Or while using cldr-data-npm, to only install needed languages ?

We get intermittent failures in our build pipeline trying to fetch the 80 or so mb of CLDR data. We filter in our package.json:

"cldr-data-urls-json": "../../cldrdatadwnl.json",
  "cldr-data-urls-filter": "(cldr-core|cldr-numbers-modern|cldr-dates-modern)",

and pull in:

// cldrdatadwnl.json
{
  "core": [
    "https://github.com/unicode-cldr/cldr-core/archive/32.0.0.zip",
    "https://github.com/unicode-cldr/cldr-numbers-modern/archive/32.0.0.zip",
    "https://github.com/unicode-cldr/cldr-dates-modern/archive/32.0.0.zip"
  ]
}

Each of these still contain the full country sets when we only need two. We also find in the install stack trace that it doesn't tell us exactly which calls failed:

{ Error: Command failed: npm install --package-lock
/var/lib/jenkins/workspace/project-QPWJTBRIABUXWNO6RXH3P2MYCI2O43T3XFIPIJKF5QHHROUWEUUQ/modules/website/node_modules/cldr-data-downloader/lib/download.js:119
      throw error;
      ^

Error: socket hang up
    at TLSSocket.onHangUp (_tls_wrap.js:1137:19)
    at Object.onceWrapper (events.js:313:30)
    at emitNone (events.js:111:20)
    at TLSSocket.emit (events.js:208:7)
    at endReadableNT (_stream_readable.js:1064:12)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! cldr-data@32.0.1 install: `node install.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the cldr-data@32.0.1 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /usr/share/jenkins/npm-cache/_logs/2018-09-11T13_28_27_730Z-debug.log

> cldr-data@32.0.1 install /var/lib/jenkins/workspace/project-QPWJTBRIABUXWNO6RXH3P2MYCI2O43T3XFIPIJKF5QHHROUWEUUQ/modules/website/node_modules/cldr-data
> node install.js

GET `https://github.com/unicode-cldr/cldr-core/archive/32.0.0.zip`
GET `https://github.com/unicode-cldr/cldr-dates-modern/archive/32.0.0.zip`
GET `https://github.com/unicode-cldr/cldr-cal-buddhist-modern/archive/32.0.0.zip`
GET `https://github.com/unicode-cldr/cldr-cal-chinese-modern/archive/32.0.0.zip`
GET `https://github.com/unicode-cldr/cldr-cal-coptic-modern/archive/32.0.0.zip`
GET `https://github.com/unicode-cldr/cldr-cal-dangi-modern/archive/32.0.0.zip`
GET `https://github.com/unicode-cldr/cldr-cal-ethiopic-modern/archive/32.0.0.zip`
GET `https://github.com/unicode-cldr/cldr-cal-hebrew-modern/archive/32.0.0.zip`
GET `https://github.com/unicode-cldr/cldr-cal-indian-modern/archive/32.0.0.zip`
GET `https://github.com/unicode-cldr/cldr-cal-islamic-modern/archive/32.0.0.zip`
GET `https://github.com/unicode-cldr/cldr-cal-japanese-modern/archive/32.0.0.zip`
GET `https://github.com/unicode-cldr/cldr-cal-persian-modern/archive/32.0.0.zip`
GET `https://github.com/unicode-cldr/cldr-cal-roc-modern/archive/32.0.0.zip`
GET `https://github.com/unicode-cldr/cldr-localenames-modern/archive/32.0.0.zip`
GET `https://github.com/unicode-cldr/cldr-misc-modern/archive/32.0.0.zip`
GET `https://github.com/unicode-cldr/cldr-numbers-modern/archive/32.0.0.zip`
GET `https://github.com/unicode-cldr/cldr-segments-modern/archive/32.0.0.zip`
GET `https://github.com/unicode-cldr/cldr-units-modern/archive/32.0.0.zip`
rxaviers commented 6 years ago

@mummybot this could be useful to you https://github.com/rxaviers/cldr-data-downloader/issues/25

mummybot commented 6 years ago

Thanks!

A random question, why did you point to the github archive (it is this connectivity which is causing us issues) with the downloader rather than npm?

https://github.com/unicode-cldr/cldr-json#installation

Installation using NPM:

$ npm install <package-name> , where <package-name> is one of the package names mentioned above, for example:

$ npm install cldr-dates-full