]> git.ipfire.org Git - thirdparty/vuejs/create-vue.git/commitdiff
fix: prioritize enviornment variables over Intl.DateTimeFormat
authorHaoqun Jiang <haoqunjiang@gmail.com>
Wed, 6 Dec 2023 05:44:49 +0000 (13:44 +0800)
committerHaoqun Jiang <haoqunjiang@gmail.com>
Wed, 6 Dec 2023 05:44:49 +0000 (13:44 +0800)
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

utils/getLanguage.ts

index 31e85830e24eb175bf651971d12dc02eae89ddb6..0f13b66ed40eb8093c7b70cb682cedf70abde831 100644 (file)
@@ -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('_', '-')