Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make locales reusable & add zh-Hant locale #365

Merged
merged 16 commits into from
Jan 25, 2024
File renamed without changes.
68 changes: 68 additions & 0 deletions locales/zh-Hant.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"projectName": {
"message": "請輸入項目名稱:"
CoolPlayLin marked this conversation as resolved.
Show resolved Hide resolved
},
"shouldOverwrite": {
"dirForPrompts": {
"current": "目前目錄:",
"target": "目標目錄:"
CoolPlayLin marked this conversation as resolved.
Show resolved Hide resolved
},
"message": "非空,是否覆蓋?"
},
"packageName": {
"message": "請輸入套件名稱:",
"invalidMessage": "無效的 package.json 名稱"
},
"needsTypeScript": {
"message": "是否使用 TypeScript 語法?"
},
"needsJsx": {
"message": "是否啟用 JSX 支援?"
},
"needsRouter": {
"message": "是否引入 Vue Router 進行單頁應用開發?"
},
"needsPinia": {
"message": "是否引進 Pinia 用於狀態管理?"
CoolPlayLin marked this conversation as resolved.
Show resolved Hide resolved
},
"needsVitest": {
"message": "是否引入 Vitest 用於單元測試"
},
"needsE2eTesting": {
"message": "是否要引入一款端對端(End to End)測試工具?",
"hint": "- 使用箭頭切換按Enter確認。",
CoolPlayLin marked this conversation as resolved.
Show resolved Hide resolved
"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": "項目建置完成,可執行以下命令:"
CoolPlayLin marked this conversation as resolved.
Show resolved Hide resolved
}
}
33 changes: 32 additions & 1 deletion utils/getLanguage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,37 @@ 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':
linkedLocale = 'zh-Hant'
break
case 'zh-HK':
linkedLocale = 'zh-Hant'
break
case 'zh-MO':
linkedLocale = 'zh-Hant'
CoolPlayLin marked this conversation as resolved.
Show resolved Hide resolved
case 'zh-CN':
linkedLocale = 'zh-Hans'
break
case 'zh-SG':
linkedLocale = 'zh-Hans'
break
default:
linkedLocale = locale
}

return linkLocale
CoolPlayLin marked this conversation as resolved.
Show resolved Hide resolved
}

function getLocale() {
const shellLocale =
Intl.DateTimeFormat().resolvedOptions().locale || // Built-in ECMA-402 support
Expand All @@ -52,7 +83,7 @@ function getLocale() {
// TODO: Windows support if needed, could consider https://www.npmjs.com/package/os-locale
'en-US' // Default fallback

const locale = shellLocale.split('.')[0].replace('_', '-')
const locale = linkLocale(shellLocale.split('.')[0].replace('_', '-'))
CoolPlayLin marked this conversation as resolved.
Show resolved Hide resolved

return locale
}
Expand Down