Skip to content

Commit 76c38a6

Browse files
committed
Localize strategy labels
1 parent a6910ba commit 76c38a6

6 files changed

Lines changed: 79 additions & 14 deletions

File tree

tests/strategy_switch_worker_validation.mjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ assert.ok(indexHtml.includes('incomeLayerStartUsdVariable = "INCOME_LAYER_START_
3434
assert.ok(indexHtml.includes('el("income-layer-mode-select").addEventListener("change"'));
3535
assert.ok(indexHtml.includes('el("income-layer-start-usd-input").addEventListener("input"'));
3636
assert.ok(indexHtml.includes('el("income-layer-max-ratio-input").addEventListener("input"'));
37+
assert.ok(indexHtml.includes('label_zh: "纳斯达克 / 标普智能定投"'));
38+
assert.ok(indexHtml.includes('localStrategyLabels'));
39+
assert.ok(indexHtml.includes('function strategyLabelSet('));
3740
assert.ok(indexHtml.includes("account-block"));
3841
assert.ok(indexHtml.includes("strategy-block"));
3942
assert.ok(indexHtml.includes("grid-template-columns: repeat(4, minmax(0, 1fr));"));
@@ -203,6 +206,7 @@ const strategyProfiles = __test.normalizeStrategyProfilesPayload(
203206
{
204207
profile: "tqqq_growth_income",
205208
label: "TQQQ Growth Income",
209+
label_zh: "TQQQ 增长收益",
206210
domain: "us_equity",
207211
runtime_enabled: true,
208212
},
@@ -215,6 +219,8 @@ const strategyProfiles = __test.normalizeStrategyProfilesPayload(
215219
],
216220
"test_strategy_profiles",
217221
);
222+
assert.equal(strategyProfiles[0].label_en, "TQQQ Growth Income");
223+
assert.equal(strategyProfiles[0].label_zh, "TQQQ 增长收益");
218224

219225
const accountOptions = __test.normalizeAccountOptionsPayload(
220226
{

web/strategy-switch-console/index.html

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -899,17 +899,29 @@ <h2 data-i18n="summary">切换摘要</h2>
899899
};
900900

901901
const defaultStrategyProfiles = [
902-
{ profile: "tqqq_growth_income", label: "TQQQ Growth Income", domain: "us_equity", runtime_enabled: true },
903-
{ profile: "soxl_soxx_trend_income", label: "SOXL/SOXX Semiconductor Trend Income", domain: "us_equity", runtime_enabled: true },
904-
{ profile: "nasdaq_sp500_smart_dca", label: "Nasdaq/S&P 500 Smart DCA", domain: "us_equity", runtime_enabled: true },
905-
{ profile: "global_etf_rotation", label: "Global ETF Rotation", domain: "us_equity", runtime_enabled: true },
906-
{ profile: "russell_1000_multi_factor_defensive", label: "Russell 1000 Multi-Factor Defensive", domain: "us_equity", runtime_enabled: true },
907-
{ profile: "mega_cap_leader_rotation_top50_balanced", label: "Mega Cap Leader Rotation Top50 Balanced", domain: "us_equity", runtime_enabled: true },
908-
{ profile: "hk_dividend_gold_defensive_rotation", label: "HK Dividend-Gold Defensive Rotation", domain: "hk_equity", runtime_enabled: true },
909-
{ profile: "hk_global_etf_tactical_rotation", label: "HK Global ETF Tactical Rotation", domain: "hk_equity", runtime_enabled: true },
910-
{ profile: "hk_low_vol_dividend_quality_snapshot", label: "HK Low-Vol Dividend Quality Snapshot", domain: "hk_equity", runtime_enabled: true },
902+
{ profile: "tqqq_growth_income", label: "TQQQ Growth Income", label_en: "TQQQ Growth Income", label_zh: "TQQQ 增长收益", domain: "us_equity", runtime_enabled: true },
903+
{ profile: "soxl_soxx_trend_income", label: "SOXL/SOXX Semiconductor Trend Income", label_en: "SOXL/SOXX Semiconductor Trend Income", label_zh: "SOXL/SOXX 半导体趋势收益", domain: "us_equity", runtime_enabled: true },
904+
{ profile: "nasdaq_sp500_smart_dca", label: "Nasdaq/S&P 500 Smart DCA", label_en: "Nasdaq/S&P 500 Smart DCA", label_zh: "纳斯达克 / 标普智能定投", domain: "us_equity", runtime_enabled: true },
905+
{ profile: "global_etf_rotation", label: "Global ETF Rotation", label_en: "Global ETF Rotation", label_zh: "全球 ETF 轮动", domain: "us_equity", runtime_enabled: true },
906+
{ profile: "russell_1000_multi_factor_defensive", label: "Russell 1000 Multi-Factor Defensive", label_en: "Russell 1000 Multi-Factor Defensive", label_zh: "罗素 1000 多因子防御", domain: "us_equity", runtime_enabled: true },
907+
{ profile: "mega_cap_leader_rotation_top50_balanced", label: "Mega Cap Leader Rotation Top50 Balanced", label_en: "Mega Cap Leader Rotation Top50 Balanced", label_zh: "美股巨头 Top50 均衡轮动", domain: "us_equity", runtime_enabled: true },
908+
{ profile: "hk_dividend_gold_defensive_rotation", label: "HK Dividend-Gold Defensive Rotation", label_en: "HK Dividend-Gold Defensive Rotation", label_zh: "港股红利黄金防御轮动", domain: "hk_equity", runtime_enabled: true },
909+
{ profile: "hk_global_etf_tactical_rotation", label: "HK Global ETF Tactical Rotation", label_en: "HK Global ETF Tactical Rotation", label_zh: "港股全球 ETF 战术轮动", domain: "hk_equity", runtime_enabled: true },
910+
{ profile: "hk_low_vol_dividend_quality_snapshot", label: "HK Low-Vol Dividend Quality Snapshot", label_en: "HK Low-Vol Dividend Quality Snapshot", label_zh: "港股低波红利质量快照", domain: "hk_equity", runtime_enabled: true },
911911
];
912912

913+
const localStrategyLabels = {
914+
tqqq_growth_income: { zh: "TQQQ 增长收益", en: "TQQQ Growth Income" },
915+
soxl_soxx_trend_income: { zh: "SOXL/SOXX 半导体趋势收益", en: "SOXL/SOXX Semiconductor Trend Income" },
916+
nasdaq_sp500_smart_dca: { zh: "纳斯达克 / 标普智能定投", en: "Nasdaq/S&P 500 Smart DCA" },
917+
global_etf_rotation: { zh: "全球 ETF 轮动", en: "Global ETF Rotation" },
918+
russell_1000_multi_factor_defensive: { zh: "罗素 1000 多因子防御", en: "Russell 1000 Multi-Factor Defensive" },
919+
mega_cap_leader_rotation_top50_balanced: { zh: "美股巨头 Top50 均衡轮动", en: "Mega Cap Leader Rotation Top50 Balanced" },
920+
hk_dividend_gold_defensive_rotation: { zh: "港股红利黄金防御轮动", en: "HK Dividend-Gold Defensive Rotation" },
921+
hk_global_etf_tactical_rotation: { zh: "港股全球 ETF 战术轮动", en: "HK Global ETF Tactical Rotation" },
922+
hk_low_vol_dividend_quality_snapshot: { zh: "港股低波红利质量快照", en: "HK Low-Vol Dividend Quality Snapshot" },
923+
};
924+
913925
const incomeLayerDefaults = {
914926
tqqq_growth_income: {
915927
startUsd: 250000,
@@ -1263,10 +1275,12 @@ <h2 data-i18n="summary">切换摘要</h2>
12631275
const domain = cleanStrategyDomain(item?.domain || "us_equity");
12641276
if (!domain) continue;
12651277
nextOptions.push(profile);
1266-
nextLabels[profile] = String(item?.label || item?.display_name || profile).trim() || profile;
1278+
nextLabels[profile] = strategyLabelSet(profile, item);
12671279
nextCatalog[profile] = {
12681280
profile,
1269-
label: nextLabels[profile],
1281+
label: nextLabels[profile].en || nextLabels[profile].zh || profile,
1282+
label_en: nextLabels[profile].en || "",
1283+
label_zh: nextLabels[profile].zh || "",
12701284
domain,
12711285
runtime_enabled: true,
12721286
};
@@ -1318,7 +1332,22 @@ <h2 data-i18n="summary">切换摘要</h2>
13181332
}
13191333

13201334
function strategyLabel(profile) {
1321-
return strategyLabels[profile] || profile;
1335+
const labels = strategyLabels[profile] || localStrategyLabels[profile];
1336+
if (!labels) return profile;
1337+
return state.lang === "zh"
1338+
? (labels.zh || labels.en || profile)
1339+
: (labels.en || labels.zh || profile);
1340+
}
1341+
1342+
function strategyLabelSet(profile, item) {
1343+
const local = localStrategyLabels[profile] || {};
1344+
const label = String(item?.label || item?.display_name || "").trim();
1345+
const labelEn = String(item?.label_en || item?.display_name_en || "").trim();
1346+
const labelZh = String(item?.label_zh || item?.display_name_zh || "").trim();
1347+
return {
1348+
zh: labelZh || local.zh || label || local.en || profile,
1349+
en: labelEn || label || local.en || labelZh || local.zh || profile,
1350+
};
13221351
}
13231352

13241353
function modeLabel(mode) {

web/strategy-switch-console/page_asset.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web/strategy-switch-console/strategy-profiles.example.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,54 +2,72 @@
22
{
33
"profile": "tqqq_growth_income",
44
"label": "TQQQ Growth Income",
5+
"label_en": "TQQQ Growth Income",
6+
"label_zh": "TQQQ 增长收益",
57
"domain": "us_equity",
68
"runtime_enabled": true
79
},
810
{
911
"profile": "soxl_soxx_trend_income",
1012
"label": "SOXL/SOXX Semiconductor Trend Income",
13+
"label_en": "SOXL/SOXX Semiconductor Trend Income",
14+
"label_zh": "SOXL/SOXX 半导体趋势收益",
1115
"domain": "us_equity",
1216
"runtime_enabled": true
1317
},
1418
{
1519
"profile": "nasdaq_sp500_smart_dca",
1620
"label": "Nasdaq/S&P 500 Smart DCA",
21+
"label_en": "Nasdaq/S&P 500 Smart DCA",
22+
"label_zh": "纳斯达克 / 标普智能定投",
1723
"domain": "us_equity",
1824
"runtime_enabled": true
1925
},
2026
{
2127
"profile": "global_etf_rotation",
2228
"label": "Global ETF Rotation",
29+
"label_en": "Global ETF Rotation",
30+
"label_zh": "全球 ETF 轮动",
2331
"domain": "us_equity",
2432
"runtime_enabled": true
2533
},
2634
{
2735
"profile": "russell_1000_multi_factor_defensive",
2836
"label": "Russell 1000 Multi-Factor Defensive",
37+
"label_en": "Russell 1000 Multi-Factor Defensive",
38+
"label_zh": "罗素 1000 多因子防御",
2939
"domain": "us_equity",
3040
"runtime_enabled": true
3141
},
3242
{
3343
"profile": "mega_cap_leader_rotation_top50_balanced",
3444
"label": "Mega Cap Leader Rotation Top50 Balanced",
45+
"label_en": "Mega Cap Leader Rotation Top50 Balanced",
46+
"label_zh": "美股巨头 Top50 均衡轮动",
3547
"domain": "us_equity",
3648
"runtime_enabled": true
3749
},
3850
{
3951
"profile": "hk_dividend_gold_defensive_rotation",
4052
"label": "HK Dividend-Gold Defensive Rotation",
53+
"label_en": "HK Dividend-Gold Defensive Rotation",
54+
"label_zh": "港股红利黄金防御轮动",
4155
"domain": "hk_equity",
4256
"runtime_enabled": true
4357
},
4458
{
4559
"profile": "hk_global_etf_tactical_rotation",
4660
"label": "HK Global ETF Tactical Rotation",
61+
"label_en": "HK Global ETF Tactical Rotation",
62+
"label_zh": "港股全球 ETF 战术轮动",
4763
"domain": "hk_equity",
4864
"runtime_enabled": true
4965
},
5066
{
5167
"profile": "hk_low_vol_dividend_quality_snapshot",
5268
"label": "HK Low-Vol Dividend Quality Snapshot",
69+
"label_en": "HK Low-Vol Dividend Quality Snapshot",
70+
"label_zh": "港股低波红利质量快照",
5371
"domain": "hk_equity",
5472
"runtime_enabled": true
5573
}

web/strategy-switch-console/strategy_profiles_asset.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web/strategy-switch-console/worker.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,6 +1004,18 @@ function normalizeStrategyProfilesPayload(payload, fieldName = "strategy profile
10041004
label: cleanLabel(item.label || item.display_name || profile, `${fieldName}[${index}].label`),
10051005
runtime_enabled: cleanProfileBoolean(item.runtime_enabled ?? item.live_enabled ?? true),
10061006
};
1007+
addConfigOptional(
1008+
entry,
1009+
"label_en",
1010+
item.label_en || item.display_name_en || item.label,
1011+
cleanLabel,
1012+
);
1013+
addConfigOptional(
1014+
entry,
1015+
"label_zh",
1016+
item.label_zh || item.display_name_zh,
1017+
cleanLabel,
1018+
);
10071019
entry.domain = cleanStrategyDomain(item.domain || "us_equity", `${fieldName}[${index}].domain`);
10081020
result.push(entry);
10091021
}

0 commit comments

Comments
 (0)