Skip to content

Commit bb11f04

Browse files
committed
fix: prioritize enviornment variables over Intl.DateTimeFormat
While `Intl.DateTimeFormat` should be the most reliable way to get the user's locale, it lacks flexibility. For example, on Windows PowerShell, there's no way to change the detection result in-session (you have to logout and login again). So in order to provide an escape hatch for developers and users who want to temporarily change the locale, we prioritize environment variables over `Intl.DateTimeFormat`. In POSIX shells, you can do `LANG=zh_CN.UTF-8` to change the locale to Chinese; In CMD, it's `set LANG=zh_CN.UTF-8`; In PowerShell, it's `$env:LANG = 'zh_CN.UTF-8'`. Closes #369
1 parent 6665f0e commit bb11f04

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

utils/getLanguage.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,10 @@ interface Language {
4545

4646
function getLocale() {
4747
const shellLocale =
48-
Intl.DateTimeFormat().resolvedOptions().locale || // Built-in ECMA-402 support
4948
process.env.LC_ALL || // POSIX locale environment variables
5049
process.env.LC_MESSAGES ||
5150
process.env.LANG ||
52-
// TODO: Windows support if needed, could consider https://www.npmjs.com/package/os-locale
51+
Intl.DateTimeFormat().resolvedOptions().locale || // Built-in ECMA-402 support
5352
'en-US' // Default fallback
5453

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

0 commit comments

Comments
 (0)