Skip to content

Commit d10070f

Browse files
Copilotmassif-01ZhuLinsen
authored
fix: 补齐 Web 设置页中文文案映射并本地下拉选项翻译 (ZhuLinsen#1453)
* Initial plan * fix: 补齐 Web 设置页中文文案映射并本地下拉选项翻译 Agent-Logs-Url: https://github.com/ZhuLinsen/daily_stock_analysis/sessions/727bf34a-aba1-484e-a33b-49b3cf2ba46c Co-authored-by: massif-01 <176381099+massif-01@users.noreply.github.com> * fix: align settings select translations --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: massif-01 <176381099+massif-01@users.noreply.github.com> Co-authored-by: Alfred <massif0601@gmail.com> Co-authored-by: ZhuLinsen <zhuls97@163.com>
1 parent 93a2251 commit d10070f

5 files changed

Lines changed: 421 additions & 7 deletions

File tree

apps/dsa-web/src/components/settings/SettingsField.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,20 @@ import { useState } from 'react';
22
import type React from 'react';
33
import { Badge, Button, Select, Input } from '../common';
44
import type { ConfigValidationIssue, SystemConfigFieldSchema, SystemConfigItem } from '../../types/systemConfig';
5-
import { getFieldDescriptionZh, getFieldTitleZh } from '../../utils/systemConfigI18n';
5+
import { getFieldDescriptionZh, getFieldOptionLabelZh, getFieldTitleZh } from '../../utils/systemConfigI18n';
66
import { cn } from '../../utils/cn';
77
import { SettingsHelpButton } from './SettingsHelpButton';
88

9-
function normalizeSelectOptions(options: SystemConfigFieldSchema['options'] = []) {
9+
function normalizeSelectOptions(key: string, options: SystemConfigFieldSchema['options'] = []) {
1010
return options.map((option) => {
1111
if (typeof option === 'string') {
12-
return { value: option, label: option };
12+
return { value: option, label: getFieldOptionLabelZh(key, option) };
1313
}
1414

15-
return option;
15+
return {
16+
...option,
17+
label: getFieldOptionLabelZh(key, option.value, option.label),
18+
};
1619
});
1720
}
1821

@@ -78,7 +81,7 @@ function renderFieldControl(
7881
id={controlId}
7982
value={value}
8083
onChange={onChange}
81-
options={normalizeSelectOptions(schema.options)}
84+
options={normalizeSelectOptions(item.key, schema.options)}
8285
disabled={disabled || !schema.isEditable}
8386
placeholder="请选择"
8487
/>

apps/dsa-web/src/components/settings/__tests__/SettingsField.test.tsx

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,82 @@ describe('SettingsField', () => {
118118
/>
119119
);
120120

121-
const select = screen.getByLabelText('NOTIFICATION_MIN_SEVERITY');
122-
expect(screen.getByRole('option', { name: 'Not set' })).not.toBeDisabled();
121+
const select = screen.getByLabelText('最小通知级别');
122+
expect(screen.getByRole('option', { name: '未设置' })).not.toBeDisabled();
123123
expect(screen.queryByRole('option', { name: '请选择' })).not.toBeInTheDocument();
124124

125125
fireEvent.change(select, { target: { value: '' } });
126126

127127
expect(onChange).toHaveBeenCalledWith('NOTIFICATION_MIN_SEVERITY', '');
128128
});
129129

130+
it('renders localized labels for real system config select options', () => {
131+
const selectCases = [
132+
{
133+
key: 'NEWS_STRATEGY_PROFILE',
134+
category: 'data_source',
135+
options: ['ultra_short', 'short', 'medium', 'long'],
136+
expectedLabels: ['超短线(1天)', '短期(3天)', '中期(7天)', '长期(30天)'],
137+
},
138+
{
139+
key: 'REPORT_TYPE',
140+
category: 'notification',
141+
options: ['simple', 'full', 'brief'],
142+
expectedLabels: ['简洁', '完整', '简报'],
143+
},
144+
{
145+
key: 'LOG_LEVEL',
146+
category: 'system',
147+
options: ['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'],
148+
expectedLabels: ['调试', '信息', '警告', '错误', '严重'],
149+
},
150+
{
151+
key: 'MARKET_REVIEW_REGION',
152+
category: 'system',
153+
options: ['cn', 'hk', 'us', 'both'],
154+
expectedLabels: ['A 股', '港股', '美股', '全部市场'],
155+
},
156+
] as const;
157+
158+
selectCases.forEach(({ key, category, options, expectedLabels }) => {
159+
const { unmount } = render(
160+
<SettingsField
161+
item={{
162+
key,
163+
value: options[0],
164+
rawValueExists: true,
165+
isMasked: false,
166+
schema: {
167+
key,
168+
title: key,
169+
category,
170+
dataType: 'string',
171+
uiControl: 'select',
172+
isSensitive: false,
173+
isRequired: false,
174+
isEditable: true,
175+
options: [...options],
176+
validation: {},
177+
displayOrder: 1,
178+
},
179+
}}
180+
value={options[0]}
181+
onChange={() => undefined}
182+
/>
183+
);
184+
185+
expectedLabels.forEach((label) => {
186+
expect(screen.getByRole('option', { name: label })).toBeInTheDocument();
187+
});
188+
189+
options.forEach((rawOption) => {
190+
expect(screen.queryByRole('option', { name: rawOption })).not.toBeInTheDocument();
191+
});
192+
193+
unmount();
194+
});
195+
});
196+
130197
it('renders context compression profile options with Chinese labels', () => {
131198
const onChange = vi.fn();
132199

0 commit comments

Comments
 (0)