From: Haoqun Jiang Date: Wed, 6 Dec 2023 05:44:49 +0000 (+0800) Subject: fix: prioritize enviornment variables over Intl.DateTimeFormat X-Git-Tag: v3.9.0~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bb11f04a5319cecde4bd6e87c3bbb1612d7a88ae;p=thirdparty%2Fvuejs%2Fcreate-vue.git 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 --- diff --git a/utils/getLanguage.ts b/utils/getLanguage.ts index 31e85830..0f13b66e 100644 --- a/utils/getLanguage.ts +++ b/utils/getLanguage.ts @@ -45,11 +45,10 @@ interface Language { function getLocale() { const shellLocale = - Intl.DateTimeFormat().resolvedOptions().locale || // Built-in ECMA-402 support process.env.LC_ALL || // POSIX locale environment variables process.env.LC_MESSAGES || process.env.LANG || - // TODO: Windows support if needed, could consider https://www.npmjs.com/package/os-locale + Intl.DateTimeFormat().resolvedOptions().locale || // Built-in ECMA-402 support 'en-US' // Default fallback const locale = shellLocale.split('.')[0].replace('_', '-')