Skip to content

Commit c27f385

Browse files
committed
Add localized strategy display names to status rows
1 parent 9d96825 commit c27f385

3 files changed

Lines changed: 19 additions & 1 deletion

File tree

src/quant_platform_kit/common/notification_localization.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@
214214
("russell_1000_multi_factor_defensive", "罗素1000多因子"),
215215
("tech_communication_pullback_enhancement", "科技通信回调增强"),
216216
("qqq_tech_enhancement", "科技通信回调增强"),
217-
("mega_cap_leader_rotation_top50_balanced", "Mega Cap Top50 平衡龙头轮动"),
217+
("mega_cap_leader_rotation_top50_balanced", "美股超大盘50强平衡龙头轮动"),
218218
("outside_monthly_execution_window", "当前不在月度执行窗口"),
219219
("no_execution_window_after_snapshot", "快照后没有可用执行窗口"),
220220
("no-op", "不执行"),

src/quant_platform_kit/common/strategies.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class StrategyMetadata:
6060
canonical_profile: str
6161
display_name: str
6262
description: str
63+
localized_display_names: Mapping[str, str] = field(default_factory=dict)
6364
aliases: tuple[str, ...] = ()
6465
cadence: str | None = None
6566
asset_scope: str | None = None
@@ -275,11 +276,21 @@ def build_strategy_index_rows(strategy_catalog: StrategyCatalog) -> list[dict[st
275276
"compatible_capabilities": definition.compatible_capabilities,
276277
"target_mode": _resolve_target_mode(definition),
277278
"bundled_config_relpath": definition.bundled_config_relpath,
279+
**_localized_display_name_fields(metadata),
278280
}
279281
)
280282
return rows
281283

282284

285+
def _localized_display_name_fields(metadata: StrategyMetadata | None) -> dict[str, object]:
286+
if metadata is None:
287+
return {}
288+
zh_name = str(metadata.localized_display_names.get("zh") or "").strip()
289+
if not zh_name:
290+
return {}
291+
return {"display_name_zh": zh_name}
292+
293+
283294
def get_catalog_target_mode(
284295
strategy_catalog: StrategyCatalog,
285296
profile: str,
@@ -441,6 +452,7 @@ def build_platform_profile_matrix(
441452
"is_default": definition.profile == policy.default_profile,
442453
"is_rollback": definition.profile == policy.rollback_profile,
443454
"domain": definition.domain,
455+
**_localized_display_name_fields(metadata),
444456
}
445457
)
446458
return rows
@@ -471,6 +483,7 @@ def build_platform_profile_status_matrix(
471483
"is_default": definition.profile == policy.default_profile,
472484
"is_rollback": definition.profile == policy.rollback_profile,
473485
"domain": definition.domain,
486+
**_localized_display_name_fields(metadata),
474487
}
475488
)
476489
return rows

tests/test_strategies.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ def test_catalog_helpers_resolve_alias_and_metadata(self) -> None:
146146
canonical_profile="global_etf_rotation",
147147
display_name="Global ETF Rotation Defense",
148148
description="rotation",
149+
localized_display_names={"zh": "全球 ETF 防守轮动"},
149150
aliases=("global_macro_etf_rotation",),
150151
cadence="quarterly",
151152
benchmark="VOO",
@@ -175,6 +176,7 @@ def test_catalog_helpers_resolve_alias_and_metadata(self) -> None:
175176
rows = build_strategy_index_rows(catalog)
176177
by_profile = {row["canonical_profile"]: row for row in rows}
177178
self.assertEqual(by_profile["global_etf_rotation"]["display_name"], "Global ETF Rotation Defense")
179+
self.assertEqual(by_profile["global_etf_rotation"]["display_name_zh"], "全球 ETF 防守轮动")
178180
self.assertEqual(by_profile["global_etf_rotation"]["target_mode"], "weight")
179181

180182
def test_platform_policy_helpers_build_matrix_and_resolve_enabled_profile(self) -> None:
@@ -185,6 +187,7 @@ def test_platform_policy_helpers_build_matrix_and_resolve_enabled_profile(self)
185187
canonical_profile="global_etf_rotation",
186188
display_name="Global ETF Rotation Defense",
187189
description="rotation",
190+
localized_display_names={"zh": "全球 ETF 防守轮动"},
188191
aliases=("global_macro_etf_rotation",),
189192
),
190193
},
@@ -204,6 +207,7 @@ def test_platform_policy_helpers_build_matrix_and_resolve_enabled_profile(self)
204207
)
205208
matrix = build_platform_profile_matrix(catalog, policy=policy)
206209
self.assertEqual(matrix[0]["display_name"], "Global ETF Rotation Defense")
210+
self.assertEqual(matrix[0]["display_name_zh"], "全球 ETF 防守轮动")
207211
definition = resolve_platform_strategy_definition(
208212
"global_macro_etf_rotation",
209213
platform_id="ibkr",
@@ -216,6 +220,7 @@ def test_platform_policy_helpers_build_matrix_and_resolve_enabled_profile(self)
216220
policy=policy,
217221
eligible_profiles=frozenset({"global_etf_rotation"}),
218222
)
223+
self.assertEqual(status_matrix[0]["display_name_zh"], "全球 ETF 防守轮动")
219224
self.assertEqual(status_matrix[0]["eligible"], True)
220225
self.assertEqual(status_matrix[0]["enabled"], True)
221226

0 commit comments

Comments
 (0)