Skip to content
This repository was archived by the owner on Jan 25, 2023. It is now read-only.

Add full-icu internationalization support in Node builds #224

Closed
danurbanowicz opened this issue Nov 21, 2018 · 8 comments
Closed

Add full-icu internationalization support in Node builds #224

danurbanowicz opened this issue Nov 21, 2018 · 8 comments

Comments

@danurbanowicz
Copy link

danurbanowicz commented Nov 21, 2018

If Netlify customers want to work with locales in Node, they'll need to have full-icu support installed, and Node does not ship with this by default. Only en-US is provided, although there have been discussions to include full-icu by default..

Support, in theory, can be added by using the npm package full-icu but it does not seem to play nicely with NVM, and it requires an environment variable or command line switch to work (disclosure: I can't get it to work).

Would it be realistic to either: build all versions of Node with full-icu support e.g. --with-intl=full-icu and live with the extra 15MB or so that it will add to the binary, or provide an option to build a version of Node with it included?

@futuregerald
Copy link

@bcomnes , just want to bring attention to this. Is it possible to allow custom node flags via environment variables that are used during node installation? I know we allow NPM_FLAGS .

@bcomnes
Copy link
Contributor

bcomnes commented May 4, 2019

Is there a way to have nvm install a node version with --with-intl=full-icu? It seems reasonable to add a similar NVM_FLAGS env var for this purpose.

@nhoizey
Copy link

nhoizey commented May 7, 2019

This would be really useful.

Currently, to show dates in French using Luxon with Eleventy, I have a (really) dirty hack:

  eleventyConfig.addFilter("displayDate", function(date) {
    return DateTime.fromJSDate(date, { zone: "Europe/Paris" })
      .setLocale("fr")
      .toLocaleString(DateTime.DATE_FULL)
      .replace(/([0-9]{4}) (M[0-9]{2}) ([0-9]{2})/, "$3 $2 $1")
      .replace(/M01/, "janvier")
      .replace(/M02/, "février")
      .replace(/M03/, "mars")
      .replace(/M04/, "avril")
      .replace(/M05/, "mai")
      .replace(/M06/, "juin")
      .replace(/M07/, "juillet")
      .replace(/M08/, "août")
      .replace(/M09/, "septembre")
      .replace(/M10/, "octobre")
      .replace(/M11/, "novembre")
      .replace(/M12/, "décembre");
});

Source here: https://github.com/nhoizey/precious-prana.com/blob/master/.eleventy.js#L14-L31

@nhoizey
Copy link

nhoizey commented Jun 18, 2019

As an alternative, would it be possible (I really don't know how it works) to have full-icu as a dependency in our projects (I'm using eleventy) to gain internationalization support?

nhoizey added a commit to nhoizey/precious-prana.com that referenced this issue Jun 28, 2019
nhoizey referenced this issue in nhoizey/precious-prana.com Jul 2, 2019
@DanailMinchev
Copy link

DanailMinchev commented Nov 9, 2019

I had the same problem when testing Gatsby and react-intl, I have installed full-icu dependency together with cross-env used with npx and on my build script I set NODE_ICU_DATA environment variable to use the data from the full-icu dependency, looks like it works for me.

Install dependency:

$ npm install full-icu

Change the build script in package.json from:

"build": "gatsby build"

to:

"build": "npx cross-env NODE_ICU_DATA=$(npx node-full-icu-path) gatsby build",

So, npx cross-env NODE_ICU_DATA=$(npx node-full-icu-path) can be used in any script, like npm start, npm install, etc

@dkokic
Copy link

dkokic commented Nov 25, 2019

How to execute npx node-full-icu-path when full-icu is installed globally?

@ehmicky
Copy link
Contributor

ehmicky commented Nov 25, 2019

Please note that since Node 13, full-icu is the default: nodejs/node#29887

@nhoizey
Copy link

nhoizey commented Nov 29, 2019

I can confirm it now works on Netlify, I've been able to remove my horrible hack! 👍

nhoizey/precious-prana.com@7311d64

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

No branches or pull requests

7 participants