-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Node is not using the system's locale #4689
Comments
This is arguably a V8 bug. It ignores locale settings. In fact, all date and number formatting logic is hard-coded. The reason it works in Chrome and Chromium is that those projects use v8-i18n on top of V8. I don't think that's a direction we want to take. It depends on libicu and that's a massive library. We would have to bundle it and that would increase our already large source tree by another 85 MB and ~500,000 LoC. |
Is there a better solution than including the v8-i18n package? |
Not really. Localization is a complex affair (the people who don't think it is are usually native English speakers) so you end up using something like libicu anyway. |
I think the docs should be fixed, currently they imply that toLocaleString will use locales. This is from the docs:
http://nodemanual.org/latest/js_doc/Number.html#Number.toLocaleString Unless nodemanual.org isn't the official doc. |
nodemanual.org isn't the official doc. :-) |
Dammit. What would you recommend using as the official doc? I've looked around a lot on this and haven't found anything. |
The latest official docs can always be found here: On Tuesday, July 30, 2013, jcollum-hcg wrote:
|
That doesn't work: the Number class isn't documented there. First hit doesn't have toLocaleString and the rest of the hits are just irc logs. |
The Number class is part of JavaScript itself, which the NodeJS docs don't re-iterate. You probably want to read up on Mozilla's MDN docs for JavaScript, or perhaps read the ECMAScript 5 reference itself. |
Right but the MDN docs don't match with V8! MDN says you can pass in a BCP 47 locale string, which works in browsers but doesn't work in Node. I've looked for a V8 API reference but haven't found any that discuss Number::toLocaleString. It's frustrating -- since this is native code I'd rather not have to read C++ to figure out what a valid signature for my function call looks like. Passing in a BCP 47 locale string clearly doesn't work in node, according to this issue ticket and my tests. |
V8 master supports linking against ICU directly now so that's an option we'll probably offer in the future. I don't think we're going to bundle ICU so you'll have to install that separately and enable it with a ./configure switch. |
I just worked around it with some regex stuff, since I didn't need full i18n. I just wish I hadn't spent so much time on this issue -- MDN says you can do X but V8 doesn't do X and there's no docs that explain that, just github bug reports. As a developer I'd like to see better docs for V8 if I'm going to continue to use it in a production environment. |
I raised this issue last year and was told that browser support for i18n is On Wed, Jul 31, 2013 at 1:34 PM, Ben Noordhuis notifications@gh.neting.ccwrote:
|
Not sure what you want me to confirm but here is a quick recap. Previously, the only way to get native i18n in V8 was through the external v8-i18 module. The V8 team recently pulled v8-i18n into V8 core (conceptually if not literally) but it still has a dependency on libicu and that's a library we're unlikely to bundle because of its massive size. We'll probably add a configure option that lets you link against an external libicu but that's something you'll have to explicitly enable at build time. tl;dr You can have native i18n but not by default. Hope that clears things up. |
@bnoordhuis could you keep this thread updated with the details (or links to them) of the approach for how people can use the v8 i18n support in Node once they're figured out? Running the latest nightly I saw there's now an |
I'll try to remember to update this issue but in case I forget, keep an eye on the ChangeLog of upcoming releases, it will be mentioned there. |
A better way to see if i18n is there is to just type "Intl" or even "new Intl.Collator();" v8 trunk, though, if enablei18n=on is on the arguments to make, has 'make dependencies" go off and download ICU (although a several year old version 4.6). So v8 doesn't include ICU source, not sure that node would need to. But it would be better to depend on a system ICU to get the latest and greatest. As far as being too big, you can slice and dice ICU lots of ways, both in code and data. Don't need 16MB of legacy mappings that aren't even used by v8? Then don't include them. We've always heard "ICU is too big!" and ".. but could you please support X?" - it takes a lot of code and data to get things right. See http://userguide.icu-project.org under packaging for more details. Anyways, v8's include of icu.gyp didn't work inside the node build, but I really don't know what I'm doing and the following only seems to result in more spectacular failure:
|
so, got node+i18n working. Steps:
Before building, needed: not too bad. Little test:
|
I followed your steps on v0.11.7 and it didn't work. Below is exactly what I've did:
And in REPL |
@medikoo i'm working on getting the full patch to post |
@srl295 thanks! Let us know |
@medikoo will do. hope to have some pull req's here soon. |
@medikoo put some patches here https://github.com/srl295/node/compare - still a work in progress. |
@srl295 great thanks, I'll watch that |
I would be ok wiht a pull request to add this functionality. Requirements:
|
@isaacs Agreed. As of v8 3.22 icu is enabled by default (using a freaking annoying gyp flag I can't figure out how to get around during configuration), but we definitely shouldn't be bundling that massive 300MB lib w/ core. behind a build flag seems appropriate. |
Could this be approached the same way that Chrome and Firefox are providing their ECMAScript Internationalization API implementations and related bundles? They are not adding anything close to 300MBs to their download sizes. When I talked with @NorbertLindenberg about this, I think it added something around 4MB to Firefox's download size. |
The increase in download size for Firefox caused by adding ICU and the ECMAScript Internationalization API varies between platforms, from 2 MB for Windows to 6 MB for Mac – the latter includes separate 32-bit and 64-bit versions of all binaries. So, as Eric said, nowhere near 300 MB. I did use a number of ICU configuration options to remove code and data that the Internationalization API doesn't need – see |
Hi,
Regards, |
@nciric good to see you last week - let me know if you need help w/ the 52 upgrade. Also the pruning should be available upstream as ICU options. Note, To put the size in perspective, see the data customizer at http://apps.icu-project.org/datacustom/ - Don't need codepage conversion? Drop 4.4MB. Don't care about Chinese collation? That's 1.2MB, etc. It takes data, and code, to get things right. |
so, 12M to 24M ( 64 bit intel linux)
|
Hi Guys! Please don't take this wrong, but the above conversation needs some perspective. Could you please provide a quick simple solution to this? We have a serious commercial SaaS product written in Node that is getting ready for initial release, and we desperately need Node to honour locales, as it should. Saying you can't because some file is too big is really letting the cart lead the horse and tail wag the dog, since the purpose of Node is to accomplish business objectives. Saying that an important function like proper locale support for Date objects can't be delivered to a major foundational software platform because some file is too large...well that just seems a bit silly. Node.js exists so that companies like ours can build business solutions with it. We are literally talking hundreds of millions of dollars in revenue here, and not being able to achieve that because some file is too large seems like priorities need to be adjusted. Do you really think we care if a file is 4 meg, 12 meg, or 300 meg? Disk is cheap and so is transfer cost. What isn't cheap is development time or forgoing serious business product release because of relatively small technical issues. I'm trying to express a real concern here, that a major function of the Node platform (namely supporting software for a global market) is being delayed even 1 day because of back and forth discussions about megabytes of disk/transfer. This was a year ago. What has happened since? Come on guys, please get this fixed ASAP so that we and others out there who banked on Node.js can get on with it. Eternally grateful! |
+1 well put @kenkopelson |
It seems like you can compile Node.js to include ICU support: |
Calling .toLocaleString() on Number and Date objects behaves differently than Chrome.
This behavior is present in Ubuntu 12.04 and OSX 10.8 using Node v0.8.17.
On Chrome:
1000.toLocaleString();
On Node:
1000.toLocaleString();
Additional info:
process.env.lang is set to the the expected value en_US.UTF-8
locale on the terminal returns the following (OSX 10.8):
LANG="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_CTYPE="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_ALL=
locale on the terminal returns the following (Ubuntu 12.04):
LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=
Related bugs: #966
The text was updated successfully, but these errors were encountered: