Skip to content

Commit

Permalink
refactor: update i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
lxxorz committed Dec 10, 2024
1 parent af620f0 commit 93b63c7
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 11 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ auto generate instruction for cursor / copilot.

<!-- commands -->

| Command | Title |
| ---------------------- | ------------------------------- |
| `cig.selectAIPrompt` | CIG: Generate Instruction |
| `cig.searchAIPrompt` | CIG: Search and Add Instruction |
| `cig.clearGlobalState` | CIG: Clear Extension State |
| Command | Title |
| ---------------------- | ------------------------------------ |
| `cig.selectAIPrompt` | CIG: Browse Instructions by Category |
| `cig.searchAIPrompt` | CIG: Search Instructions by Keyword |
| `cig.clearGlobalState` | CIG: Clear Extension State |

<!-- commands -->

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@
"commands": [
{
"command": "cig.selectAIPrompt",
"title": "Generate Instruction",
"title": "Browse Instructions by Category",
"category": "CIG"
},
{
"command": "cig.searchAIPrompt",
"title": "Search and Add Instruction",
"title": "Search Instructions by Keyword",
"category": "CIG"
},
{
Expand Down
22 changes: 20 additions & 2 deletions src/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,27 @@ interface LocalizedMessages {
yes: string
no: string
configEnableAutoDetect: string
confirmOverwrite: string
overwrite: string
}

const zhCN: LocalizedMessages = {
searchPlaceholder: '搜索规则...',
noAIConfigFound: '未检测到 AI 配置文件。是否要创建一个?',
searchAndCreate: '搜索并创建',
ignoreProject: '忽略项目',
cancel: '取消',
ruleAddedSuccess: (title: string) => `规则 "${title}" 添加成功`,
clearStateConfirm: '确定要清除所有已保存的扩展状态吗?这将重置所有被忽略的项目。',
clearStateSuccess: '扩展状态已清除',
yes: '是',
no: '否',
configEnableAutoDetect: '自动检测并提示创建 AI 配置文件',
confirmOverwrite: '这将覆盖现有的 AI 配置文件。是否继续?',
overwrite: '覆盖',
}

const enUS: LocalizedMessages = {
searchPlaceholder: 'Search rules...',
noAIConfigFound: 'No AI config file detected. Would you like to create one?',
searchAndCreate: 'Search and Create',
Expand All @@ -26,10 +44,10 @@ const zhCN: LocalizedMessages = {
yes: 'Yes',
no: 'No',
configEnableAutoDetect: 'Automatically detect and prompt to create AI config files',
confirmOverwrite: 'This will overwrite the existing AI config file. Do you want to continue?',
overwrite: 'Overwrite',
}

const enUS: LocalizedMessages = { ...zhCN }

const messages: Record<string, LocalizedMessages> = {
'zh-cn': zhCN,
'en': enUS,
Expand Down
13 changes: 11 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,17 @@ export function activate(context: vscode.ExtensionContext) {
async function writeRuleToFile(sections: Section[]) {
const rule = findCurrentRule(sections)
if (rule) {
await insertPromptToFile(rule.content)
vscode.window.showInformationMessage(`Rule "${currentRule}" written successfully.`)
const messages = getLocaleMessages()
const result = await vscode.window.showWarningMessage(
messages.confirmOverwrite,
messages.overwrite,
messages.cancel
)

if (result === messages.overwrite) {
await insertPromptToFile(rule.content)
vscode.window.showInformationMessage(messages.ruleAddedSuccess(currentRule!))
}
}
}

Expand Down

0 comments on commit 93b63c7

Please sign in to comment.