Skip to content

Commit d0cd083

Browse files
committed
refactor: improve locale detection
ECMA-402 support in Node.js should be reliable now, as it's building with full-icu by default since Node.js 13. So I made it the first choice. Actually, I'm not even sure if the remaining variables are still useful. But if they are used, here are my modifications: - As for POSIX environment variables, I chose `LC_MESSAGES` over `LC_CTYPE`, as it better reflects the purpose of the usage (we are using the detection result to show prompt messages). - I removed `LANGSPEC` because I can't find any documentation of it except for one single mention in Wikipedia. I can't find any real usage of it on my Windows machine. - As we no longer use `LC_CTYPE`, it seems that `C` is no longer a possible value for `shellLocale`, so I removed the fallback check logic. If no more bug reports of Windows users are received in the coming months, I think we can remove the TODO comment entirely.
1 parent 8fbe012 commit d0cd083

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

utils/getLanguage.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,16 @@ interface Language {
4343

4444
function getLocale() {
4545
const shellLocale =
46-
process.env.LC_ALL ||
47-
process.env.LANG || // Unix maybe
48-
process.env.LC_CTYPE || // C libraries maybe
49-
process.env.LANGSPEC || // Windows maybe
50-
Intl.DateTimeFormat().resolvedOptions().locale || // Node.js - Internationalization support
51-
'en-US'
46+
Intl.DateTimeFormat().resolvedOptions().locale || // Built-in ECMA-402 support
47+
process.env.LC_ALL || // POSIX locale environment variables
48+
process.env.LC_MESSAGES ||
49+
process.env.LANG ||
50+
// TODO: Windows support if needed, could consider https://www.npmjs.com/package/os-locale
51+
'en-US' // Default fallback
5252

5353
const locale = shellLocale.split('.')[0].replace('_', '-')
5454

55-
// locale might be 'C' or something else
56-
return locale.length < 5 ? 'en-US' : locale
55+
return locale
5756
}
5857

5958
export default function getLanguage() {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy