Skip to content

Commit 77399f6

Browse files
committed
feat(i18n): optimize /config configuration display
- Show current locale value next to each category name (e.g. 'Language (en)') - Translate locale option labels ('English'/'中文') via t() lookup - Replace hardcoded 'current' with t('ui.config.currentLabel') - Remove unused useMemo import (fixes lint warning) - Add 4 new translation keys: currentLabel, localeEn, localeZhCN, categoryWithValue (240 total keys)
1 parent 2c44eb1 commit 77399f6

3 files changed

Lines changed: 46 additions & 16 deletions

File tree

locales/en/ui-config.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
"replyLanguage": "Reply Language",
88
"selectLanguage": "Select Language",
99
"selectCategoryHelp": "Space/Enter select · Esc to cancel",
10-
"selectLanguageHelp": "Space/Enter apply · Esc back"
10+
"selectLanguageHelp": "Space/Enter apply · Esc back",
11+
"currentLabel": "current",
12+
"localeEn": "English",
13+
"localeZhCN": "\u4e2d\u6587",
14+
"categoryWithValue": "{label} ({value})"
1115
}
1216
}
1317
}

locales/zh-CN/ui-config.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
"replyLanguage": "回复语言",
88
"selectLanguage": "选择语言",
99
"selectCategoryHelp": "空格/回车选择 · Esc 取消",
10-
"selectLanguageHelp": "空格/回车确认 · Esc 返回"
10+
"selectLanguageHelp": "空格/回车确认 · Esc 返回",
11+
"currentLabel": "当前",
12+
"localeEn": "English",
13+
"localeZhCN": "中文",
14+
"categoryWithValue": "{label}({value})"
1115
}
1216
}
1317
}

src/ui/components/ConfigDropdown/index.tsx

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect, useMemo, useState } from "react";
1+
import React, { useEffect, useState } from "react";
22
import { useInput } from "ink";
33
import DropdownMenu from "../../DropdownMenu";
44
import { t, type Locale } from "../../../common/i18n";
@@ -8,20 +8,38 @@ type ConfigStep = "category" | "language";
88
type CategoryOption = {
99
key: "locale" | "thinkingLocale" | "replyLocale";
1010
label: string;
11+
description: string;
1112
};
1213

13-
function getCategoryOptions(): CategoryOption[] {
14+
function getLocaleDisplayName(locale: Locale): string {
15+
return locale === "en" ? t("ui.config.localeEn") : t("ui.config.localeZhCN");
16+
}
17+
18+
function getCategoryOptions(
19+
currentLocale: Locale,
20+
currentThinkingLocale: Locale,
21+
currentReplyLocale: Locale
22+
): CategoryOption[] {
1423
return [
15-
{ key: "locale", label: t("ui.config.language") },
16-
{ key: "thinkingLocale", label: t("ui.config.thinkingLanguage") },
17-
{ key: "replyLocale", label: t("ui.config.replyLanguage") },
24+
{
25+
key: "locale",
26+
label: t("ui.config.language"),
27+
description: getLocaleDisplayName(currentLocale),
28+
},
29+
{
30+
key: "thinkingLocale",
31+
label: t("ui.config.thinkingLanguage"),
32+
description: getLocaleDisplayName(currentThinkingLocale),
33+
},
34+
{
35+
key: "replyLocale",
36+
label: t("ui.config.replyLanguage"),
37+
description: getLocaleDisplayName(currentReplyLocale),
38+
},
1839
];
1940
}
2041

21-
const LOCALE_OPTIONS: { key: Locale; label: string }[] = [
22-
{ key: "en", label: "English" },
23-
{ key: "zh-CN", label: "中文" },
24-
];
42+
const LOCALE_OPTIONS: { key: Locale }[] = [{ key: "en" }, { key: "zh-CN" }];
2543

2644
type Props = {
2745
open: boolean;
@@ -73,7 +91,7 @@ const ConfigDropdown: React.FC<Props> = ({
7391

7492
function handleSelect(): void {
7593
if (step === "category") {
76-
const category = getCategoryOptions()[activeIndex];
94+
const category = getCategoryOptions(currentLocale, currentThinkingLocale, currentReplyLocale)[activeIndex];
7795
if (!category) {
7896
return;
7997
}
@@ -110,7 +128,10 @@ const ConfigDropdown: React.FC<Props> = ({
110128
return;
111129
}
112130

113-
const optionCount = step === "category" ? getCategoryOptions().length : LOCALE_OPTIONS.length;
131+
const optionCount =
132+
step === "category"
133+
? getCategoryOptions(currentLocale, currentThinkingLocale, currentReplyLocale).length
134+
: LOCALE_OPTIONS.length;
114135

115136
if (key.upArrow) {
116137
setActiveIndex((idx) => (idx - 1 + optionCount) % optionCount);
@@ -143,15 +164,16 @@ const ConfigDropdown: React.FC<Props> = ({
143164

144165
const items =
145166
step === "category"
146-
? getCategoryOptions().map((option) => ({
167+
? getCategoryOptions(currentLocale, currentThinkingLocale, currentReplyLocale).map((option) => ({
147168
key: option.key,
148169
label: option.label,
170+
description: option.description,
149171
selected: false,
150172
}))
151173
: LOCALE_OPTIONS.map((option) => ({
152174
key: option.key,
153-
label: option.label,
154-
description: option.key === getCurrentLocaleForCategory(selectedCategory!) ? "current" : "",
175+
label: getLocaleDisplayName(option.key),
176+
description: option.key === getCurrentLocaleForCategory(selectedCategory!) ? t("ui.config.currentLabel") : "",
155177
selected: option.key === getCurrentLocaleForCategory(selectedCategory!),
156178
}));
157179

0 commit comments

Comments
 (0)