]> git.ipfire.org Git - thirdparty/vuejs/create-vue.git/commitdiff
feat: make locales reusable & add zh-Hant locale (#365)
authorCoolPlayLin <coolplaylin@qq.com>
Thu, 25 Jan 2024 03:43:44 +0000 (11:43 +0800)
committerGitHub <noreply@github.com>
Thu, 25 Jan 2024 03:43:44 +0000 (11:43 +0800)
Co-authored-by: btea <2356281422@qq.com>
Co-authored-by: Haoqun Jiang <haoqunjiang@gmail.com>
Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
locales/zh-Hans.json [moved from locales/zh-CN.json with 100% similarity]
locales/zh-Hant.json [new file with mode: 0644]
utils/getLanguage.ts

similarity index 100%
rename from locales/zh-CN.json
rename to locales/zh-Hans.json
diff --git a/locales/zh-Hant.json b/locales/zh-Hant.json
new file mode 100644 (file)
index 0000000..e1901ed
--- /dev/null
@@ -0,0 +1,68 @@
+{
+  "projectName": {
+    "message": "請輸入專案名稱:"
+  },
+  "shouldOverwrite": {
+    "dirForPrompts": {
+      "current": "當前資料夾",
+      "target": "目標資料夾:"
+    },
+    "message": "非空,是否覆蓋?"
+  },
+  "packageName": {
+    "message": "請輸入套件名稱:",
+    "invalidMessage": "無效的 package.json 名稱"
+  },
+  "needsTypeScript": {
+    "message": "是否使用 TypeScript 語法?"
+  },
+  "needsJsx": {
+    "message": "是否啟用 JSX 支援?"
+  },
+  "needsRouter": {
+    "message": "是否引入 Vue Router 進行單頁應用開發?"
+  },
+  "needsPinia": {
+    "message": "是否引入 Pinia 用於狀態管理?"
+  },
+  "needsVitest": {
+    "message": "是否引入 Vitest 用於單元測試"
+  },
+  "needsE2eTesting": {
+    "message": "是否要引入一款端對端(End to End)測試工具?",
+    "hint": "- 使用箭頭切換按 Enter 確認。",
+    "selectOptions": {
+      "negative": {
+        "title": "不需要"
+      },
+      "cypress": {
+        "title": "Cypress",
+        "desc": "同時支援基於 Cypress Component Testing 的單元測試"
+      },
+      "nightwatch": {
+        "title": "Nightwatch",
+        "desc": "同時支援基於 Nightwatch Component Testing 的單元測試"
+      },
+      "playwright": {
+        "title": "Playwright"
+      }
+    }
+  },
+  "needsEslint": {
+    "message": "是否引入 ESLint 用於程式碼品質檢測?"
+  },
+  "needsPrettier": {
+    "message": "是否引入 Prettier 用於程式碼格式化?"
+  },
+  "errors": {
+    "operationCancelled": "操作取消"
+  },
+  "defaultToggleOptions": {
+    "active": "是",
+    "inactive": "否"
+  },
+  "infos": {
+    "scaffolding": "正在建置專案",
+    "done": "專案建置完成,可執行以下命令:"
+  }
+}
index 4f7ec42a60f1e6e5866f54e246db285d7eb9d2c8..b0de77bd12dd8eb0ae4b425df63b413b666e5396 100644 (file)
@@ -43,6 +43,32 @@ interface Language {
   }
 }
 
+/**
+ *
+ * This function is used to link obtained locale with correct locale file in order to make locales reusable
+ *
+ * @param locale the obtained locale
+ * @returns locale that linked with correct name
+ */
+function linkLocale(locale: string) {
+  let linkedLocale: string
+  switch (locale) {
+    case 'zh-TW':
+    case 'zh-HK':
+    case 'zh-MO':
+      linkedLocale = 'zh-Hant'
+      break
+    case 'zh-CN':
+    case 'zh-SG':
+      linkedLocale = 'zh-Hans'
+      break
+    default:
+      linkedLocale = locale
+  }
+
+  return linkedLocale
+}
+
 function getLocale() {
   const shellLocale =
     process.env.LC_ALL || // POSIX locale environment variables
@@ -51,9 +77,7 @@ function getLocale() {
     Intl.DateTimeFormat().resolvedOptions().locale || // Built-in ECMA-402 support
     'en-US' // Default fallback
 
-  const locale = shellLocale.split('.')[0].replace('_', '-')
-
-  return locale
+  return linkLocale(shellLocale.split('.')[0].replace('_', '-'))
 }
 
 export default function getLanguage() {