Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter available languages #60

Open
lmaillet opened this issue Jun 29, 2018 · 8 comments
Open

Filter available languages #60

lmaillet opened this issue Jun 29, 2018 · 8 comments

Comments

@lmaillet
Copy link

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
Copy link
Owner

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
Copy link
Author

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
Copy link
Owner

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
Copy link
Author

Works great, you're a hero !

@rxaviers
Copy link
Owner

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

@mummybot
Copy link

mummybot commented Sep 11, 2018

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! [email protected] install: `node install.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] 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

> [email protected] 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
Copy link
Owner

@mummybot this could be useful to you rxaviers/cldr-data-downloader#25

@mummybot
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants