1616from notifications .events import NotificationPublisher
1717from notifications import renderers as notification_renderers
1818from quant_platform_kit .common .models import PortfolioSnapshot , Position
19+ from quant_platform_kit .common .notification_localization import (
20+ localize_notification_text as _base_localize_notification_text ,
21+ translator_uses_zh as _base_translator_uses_zh ,
22+ )
1923from quant_platform_kit .common .port_adapters import CallableNotificationPort , CallablePortfolioPort
2024
2125
22- _ZH_REASON_REPLACEMENTS = (
23- ("feature snapshot guard blocked execution" , "特征快照校验阻止执行" ),
24- ("feature snapshot required" , "需要特征快照" ),
25- ("feature snapshot compute failed" , "特征快照计算失败" ),
26- ("feature_snapshot_download_failed" , "特征快照下载失败" ),
27- ("feature_snapshot_compute_failed" , "特征快照计算失败" ),
28- ("feature_snapshot_path_missing" , "缺少特征快照路径" ),
29- ("feature_snapshot_missing" , "特征快照不存在" ),
30- ("feature_snapshot_stale" , "特征快照过旧" ),
31- ("feature_snapshot_manifest_missing" , "缺少快照清单" ),
32- ("feature_snapshot_profile_mismatch" , "快照策略名不匹配" ),
33- ("feature_snapshot_config_name_mismatch" , "快照配置名不匹配" ),
34- ("feature_snapshot_config_path_mismatch" , "快照配置路径不匹配" ),
35- ("feature_snapshot_contract_version_mismatch" , "快照契约版本不匹配" ),
36- ("soxl_soxx_trend_income" , "SOXL/SOXX 半导体趋势收益" ),
37- ("tqqq_growth_income" , "TQQQ 增长收益" ),
38- ("global_etf_rotation" , "全球 ETF 轮动" ),
39- ("russell_1000_multi_factor_defensive" , "罗素1000多因子" ),
40- ("tech_communication_pullback_enhancement" , "科技通信回调增强" ),
41- ("qqq_tech_enhancement" , "科技通信回调增强" ),
42- ("mega_cap_leader_rotation_aggressive" , "Mega Cap 激进龙头轮动" ),
43- ("mega_cap_leader_rotation_dynamic_top20" , "Mega Cap 动态 Top20 龙头轮动" ),
44- ("mega_cap_leader_rotation_top50_balanced" , "Mega Cap Top50 平衡龙头轮动" ),
45- ("dynamic_mega_leveraged_pullback" , "Mega Cap 2x 回调策略" ),
46- ("outside_monthly_execution_window" , "当前不在月度执行窗口" ),
47- ("no_execution_window_after_snapshot" , "快照后没有可用执行窗口" ),
48- ("no-op" , "不执行" ),
49- ("monthly snapshot cadence" , "月度快照节奏" ),
50- ("waiting inside execution window" , "等待进入执行窗口" ),
51- ("small_account_warning=true" , "小账户提示=是" ),
52- ("portfolio_equity=" , "净值=" ),
53- ("min_recommended_equity=" , "建议最低净值=" ),
54- (
55- "integer_shares_min_position_value_may_prevent_backtest_replication" ,
56- "整数股和最小仓位限制可能导致实盘无法完全复现回测" ,
57- ),
58- (
59- "integer-share minimum position sizing may prevent backtest replication" ,
60- "整数股和最小仓位限制可能导致实盘无法完全复现回测" ,
61- ),
62- ("small account warning: portfolio equity" , "小账户提示:净值" ),
63- ("small account warning" , "小账户提示" ),
64- ("is below the recommended" , "低于建议" ),
65- ("is below recommended" , "低于建议" ),
66- ("snapshot_as_of=" , "快照日期=" ),
67- ("snapshot=" , "快照日期=" ),
68- ("allowed=" , "允许日期=" ),
69- ("<unknown>" , "未知" ),
70- ("<none>" , "无" ),
71- ("RISK-ON" , "风险开启" ),
72- ("DE-LEVER" , "降杠杆" ),
73- ("regime=hard_defense" , "市场阶段=强防御" ),
74- ("regime=soft_defense" , "市场阶段=软防御" ),
75- ("regime=risk_on" , "市场阶段=进攻" ),
76- ("benchmark_trend=down" , "基准趋势=向下" ),
77- ("benchmark_trend=up" , "基准趋势=向上" ),
78- ("benchmark=down" , "基准趋势=向下" ),
79- ("benchmark=up" , "基准趋势=向上" ),
80- ("breadth=" , "市场宽度=" ),
81- ("target_stock=" , "目标股票仓位=" ),
82- ("realized_stock=" , "实际股票仓位=" ),
83- ("stock_exposure=" , "股票目标仓位=" ),
84- ("safe_haven=" , "避险仓位=" ),
85- ("selected=" , "入选标的数=" ),
86- ("top=" , "前排标的=" ),
87- ("no_selection" , "无入选标的" ),
88- ("outside_execution_window" , "当前不在执行窗口" ),
26+ _EXTRA_ZH_REASON_REPLACEMENTS = (
8927 ("pending_orders_detected" , "检测到未完成订单" ),
9028 ("same_day_execution_locked" , "当日执行锁已存在" ),
9129 ("same_day_fills_detected" , "检测到当日成交" ),
92- ("insufficient_buying_power" , "购买力不足" ),
93- ("missing_price" , "缺少报价" ),
94- ("no_equity" , "无净值" ),
95- ("fail_closed" , "关闭执行" ),
96- ("reason=" , "原因=" ),
9730 ("fail_reason=" , "失败原因=" ),
9831 ("decision=" , "决策=" ),
9932)
@@ -117,18 +50,15 @@ def _format_symbol_preview(symbols, *, limit: int = 3) -> str:
11750
11851
11952def _translator_uses_zh (translator ) -> bool :
120- sample = str (translator ("no_trades" ))
121- return any ("\u4e00 " <= ch <= "\u9fff " for ch in sample )
53+ return _base_translator_uses_zh (translator )
12254
12355
12456def _localize_notification_text (text : str , * , translator ) -> str :
125- value = str (text or "" ).strip ()
126- if not value or not _translator_uses_zh (translator ):
127- return value
128- localized = value
129- for source , target in _ZH_REASON_REPLACEMENTS :
130- localized = localized .replace (source , target )
131- return localized
57+ return _base_localize_notification_text (
58+ text ,
59+ translator = translator ,
60+ extra_replacements = _EXTRA_ZH_REASON_REPLACEMENTS ,
61+ )
13262
13363
13464def _render_notification_context_text (
0 commit comments