Node: Node respects LANG env var, but not LC_TIME, LC_NUMERIC, LC_MONETARY, ...

Created on 7 Oct 2018  路  12Comments  路  Source: nodejs/node

  • Version: v10.10.0
  • Platform: Darwin Felix-MBP 18.0.0 Darwin Kernel Version 18.0.0: Wed Aug 22 20:13:40 PDT 2018; root:xnu-4903.201.2~1/RELEASE_X86_64 x86_64


I live in non-English country, but have my OS language set to English. This is helpful for many reasons, for example error messages are easier to google, instructions are easier to follow and labels are usually shorter.
Despite a different language, I still otherwise have configured to use a non-English locale (e.g. use 24h time).

In Node, if compiled with full ICU or with NODE_ICU_DATA set, new Date().toLocaleString() returns 12h time format.
If I set the LANG env var to de-DE, I get 24h time. But that implies that the _language_ should be German, which it should not, the language should be English.

But any Unix env vars for setting only the locale or specific parts of the locale, such as LC_TIME, LC_MONETARY etc are not respected. With LC_TIME=de_DE and without LANG set, Node still uses 12h format.

Node should respect these.

Reference: http://pubs.opengroup.org/onlinepubs/7908799/xbd/envvar.html

i18n-api

Most helpful comment

FTR and in the spirit of cross-platformity, need to remember Windows usualy keeps this information in the registry, not in the environment block, and it is abstracted by the GetLocaleInfo[Ex] syscall.

All 12 comments

cc @nodejs/intl

This is an upstream issue. ICU, the i18n/intl library that Node.js and V8 use, only looks at the LANG and LC_ALL environment variables.

If V8 uses it, what does Chrome do? I noticed that Chrome respects the macOS system preferences, which can be configured to e.g. use English language but 24h time:

image

image

How does Chrome achieve this?

/cc @srl295

@felixfbecker Chrome may read the preference data directly. Yes, LANG is used to set the overall locale. I'm not sure what Chrome does exactly but we could look into moving the Chrome code into v8 itself and/or Node. (Thanks for the ping @jasnell in mid sentence)

FTR and in the spirit of cross-platformity, need to remember Windows usualy keeps this information in the registry, not in the environment block, and it is abstracted by the GetLocaleInfo[Ex] syscall.

If V8 uses it, what does Chrome do? I noticed that Chrome respects the macOS system preferences

Chrome may read the preference data directly.

That's right. For the curious, the relevant code is in chromium's src/ui/base/l10n directory. Specifically for macos, it uses NSLocale.

we could look into moving the Chrome code into v8

There's a lot of platform-specific code involved. The V8 people have said in the past they don't want to be in that business.

It could be an option for Node.js but someone has to write it. You can't just lift the chromium code, too many dependencies.

@bnoordhuis if v8 doesn't want to be in that business, Node really doesn't want to have such platform specific code, I don't think.

@felixfbecker could you raise an issue with ICU over at https://unicode-org.atlassian.net mentioning this issue?

@srl295 Is this not-a-bug? Or blocked-on-something before we can fix it? Or something we need to fix and we just aren't sure exactly how yet?

The immediate issue is an upstream issue (ICU only honoring LANG and LC_ALL.)

It's not completely out of the question to fix it in Node.js but if no one is going to work on it, we might as well close this out.

Since no one has spoken up I'll take the liberty of closing this out. Let me know if (and why) I should reopen.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

stevenvachon picture stevenvachon  路  3Comments

jmichae3 picture jmichae3  路  3Comments

willnwhite picture willnwhite  路  3Comments

mcollina picture mcollina  路  3Comments

dfahlander picture dfahlander  路  3Comments