Skip to content

[UI] Unify currency formatting onto the i18n locale policy (lib/money vs @finagent/i18n) #86

Closed

Description

@yjg-djb

Background

在 #70 的排查中发现:UI 层同时存在两套 locale 策略的货币/数字格式化器,且在同一界面混用,导致输出不一致。

  • packages/ui/src/lib/money.ts:formatMoney 使用 Intl.NumberFormat(undefined, …) —— 跟随操作系统 locale;
  • packages/i18n/src/format.ts:formatCurrency 使用 localeOf(locale) → i18n 的 currentLocale(应用内语言选择,默认 en-US)。

后果(实测,zh-CN Windows):

  • TodayView 同屏出现 PortfolioCard(i18n 路径)的 $12,345.67 与 Watchlist movers(lib/money 路径,TodayView.tsx:192)的 US$100.00 混排;
  • 应用内语言设置与货币呈现脱钩:用户把界面语言切到 zh-CN,卡片仍是 $;切到 en-US 的用户在 zh-CN 系统上仍看到 US$;
  • 同一数值在不同组件间格式不可比。

消费方规模:lib/money 家族(formatMoney/formatSignedMoney/formatPercent/formatQuantity/formatFreshness)在 UI 内约 5 处非测试导入;@finagent/i18n 格式化家族约 11 处。两套 API 语义高度重叠(货币、带符号货币、百分比、数量分组)。

Requirements

  • 确定唯一 locale 权威:应用内 i18n locale(currentLocale,跟随语言设置)——这是既有 i18n 架构(docs/I18N.md、setLocale)的自然延伸;系统 locale 不应参与货币呈现;
  • 将 lib/money 的格式化语义迁移/收敛到 @finagent/i18n(或 lib/money 内部委托 i18n formatter),保持调用方签名兼容或一次性迁移调用点;
  • 不支持的货币代码回退行为(plain number + ISO code)保持不变;
  • 同一视图中同一货币的呈现必须一致(TodayView 为验收场景);
  • 与 [Privacy] Centralize redaction and data minimization for logs, diagnostics, traces, and eval artifacts #19 的 privacy 模块无耦合,纯 UI/i18n 层改动。

Acceptance Criteria

  • lib/money 与 @finagent/i18n 不再存在并行的 locale 策略;货币/数字格式化只有一个规则源;
  • 界面语言切换(en-US ↔ zh-CN)后,货币呈现随之切换($1,234.56 ↔ US$1,234.56);
  • TodayView 等混用视图不再出现同屏混排;
  • 相关单测覆盖两种 locale 下的输出(可注入 locale,参照 formatDate 已有的模式);
  • CI 三道 gate 全绿。

Notes

此问题最初在 #70 的 PR 描述中作为顺带观察提出(含实测截图级证据:同屏 Total Value$12,345.67 与 US$100.00)。如方向认可我可以直接认领实施。

Activity

  1. yjg-djb commented on Sep 11, 2026

    @yjg-djb
    ContributorAuthor

    /claim

  2. added
    claimed
    on Sep 11, 2026
  3. github-actions commented on Sep 11, 2026

    @github-actions

    @yjg-djb 已认领该 Issue,并已自动设为 Assignee。提交 PR 时请在描述中写 Closes #86。

  4. added a commit that references this issue on Sep 11, 2026
    8c3423f
  5. added a commit that references this issue on Sep 11, 2026
    3ce3848
  6. added 2 commits that reference this issue on Sep 12, 2026
    c6feb42
    e3f5134
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

claimed

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions