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?
@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 .
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.
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
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?
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
How to execute npx node-full-icu-path when full-icu is installed globally?
Please note that since Node 13, full-icu is the default: https://github.com/nodejs/node/pull/29887
I can confirm it now works on Netlify, I've been able to remove my horrible hack! 馃憤
https://github.com/nhoizey/precious-prana.com/commit/7311d64c0c2f6f005a35bc2259f816c75428fc44
Most helpful comment
Please note that since Node 13,
full-icuis the default: https://github.com/nodejs/node/pull/29887