mirror of
https://github.com/panatgithub/AnkiHeadingSync.git
synced 2026-07-22 17:10:28 +00:00
- 新增完整双语 i18n 支持,支持按 Obsidian 语言自动切换 - 实现结构化 warning / user error 渲染 - Added full bilingual i18n support with automatic switching based on Obsidian language settings - Implemented structured warning and user error rendering
3 KiB
3 KiB
i18n Decisions
1. 实现入口
本轮继续沿用现有分层,不做额外框架化改造:
src/presentation/i18n/放 locale、消息字典、t()、formatList()。- 展示层入口继续是
AnkiHeadingSyncPlugin、registerCommands、PluginSettingTab、EmptyDeckSelectionModal、NoticeService。 - 结构化用户错误定义放在
src/application/errors/,供 application / presentation 共用。
2. locale 策略
- 运行时唯一来源是
obsidian.getLanguage()。 - 仅当返回值严格等于
zh时使用简体中文。 - 其他所有语言码都回退到英文,包括
en、en-GB、ja、zh-TW。 - 不缓存 locale 常量;
t()与renderUserMessage()每次调用都重新解析当前语言。
3. message 结构
按计划固定以下 key 分组:
commands.*settings.*modal.emptyDeck.*notice.*errors.*warnings.deck.*
zh.ts 通过 satisfies typeof en 约束字典 shape,避免漏 key。
4. 用户错误模型
- 新增
PluginUserError,仅承载key与params。 - 新增
isPluginUserError()与renderUserMessage()。 - 插件自有、会冒泡到 Notice/UI 的错误统一抛
PluginUserError。 - 未结构化的第三方或底层异常继续允许透传
error.message作为诊断信息。
5. warning / failure 结构
DeckResolutionWarning改为{ filePath, code, params? }。getDeckResolutionWarningKey()使用filePath + code + stable(params)去重,不再依赖最终展示文案。- deck 相关领域服务只输出 warning code/params;最终显示由
NoticeService渲染。 - clear/reset/write-back 类失败项也改为结构化
code + params,避免 lower layer 直接生成最终字符串。
6. 设置页集成方式
- 保持现有 imperative render,不引入新的设置元描述层。
- 所有标题、说明、按钮、状态文案、preview、dropdown label、scope 文案、aria-label 直接切到
t()。 - 动态状态统一改成 key + params,而不是继续内联拼接。
- note type、field name、deck name、folder path 等业务数据原样透传,不做翻译。
7. 仓库兼容性偏差
相对草案,采用以下更贴合仓库的落地方式:
PluginUserError放在 application 层而不是 presentation 层,因为validatePluginSettings()、ManualSyncService、NoteFieldMappingService都在 application。NoticeService负责 summary、warning 列表和结构化 failure 的最终格式化,避免在 plugin 主类里重复拼接。- 对
pluginState中持久化的deckWarnings直接升级为结构化 payload,不做兼容旧 message 字段的额外迁移逻辑,因为本任务明确不要求 settings schema 迁移,且 warning 不属于设置 schema。
8. 验证策略
- 先做 locale / i18n 单测,确保基础设施稳定。
- 再补 settings / modal / notice 的双语表现测试。
- 最后更新 error / warning / persistence 相关测试,跑完整
npm test、npm run build、npm run lint。