Added intsuffix - #1
Conversation
|
Thanks for the PR! Please also add it to |
for more information, see https://pre-commit.ci
Codecov Report
@@ Coverage Diff @@
## main #1 +/- ##
=======================================
Coverage ? 99.69%
=======================================
Files ? 9
Lines ? 659
Branches ? 0
=======================================
Hits ? 657
Misses ? 2
Partials ? 0
Flags with carried forward coverage won't be shown. Click here to find out more. Continue to review full report at Codecov.
|
|
Thinking about the name Would |
|
Closing in favour of #22 which should more-or-less cover this too. Thanks! |
M1 — i18n 接入(moonbit/src/humanize/number.mbt) 将 apnumber / fractional / scientific / ordinal 的用户可见文案路由到 gettext: apnumber → gettext(words[n]) fractional → gettext(...)(纯分数与带分数两条路径) scientific → gettext(sign + mant_str + " x 10" + exp_str) ordinal → gettext(n.to_string() + suffix) 未配置语言区域 / 英文时自动回退为原词,既有 number_test.mbt 断言不受影响。 M2 — Native 时钟补全(clock_native.mbt + moon.pkg) 新增 clock_native.mbt(target: ["native"]),提供 now() -> Int64(复用 @env.now()),解决 gap-spec python-humanize#1.4 的 native 链接失败 / "未注入时钟" panic。 M3 — WASM 导出层(wasm.mbt + moon.pkg) 新增 wasm.mbt(target: ["wasm","wasm-gc"])作为显式 wasm 入口标记(wasm_version / wasm_ready 探针)。为避免同包 pub fn 重名冲突,未重复导出已有公开函数——根包 moonbit/moonbit.mbt 已是 preferred_target=wasm 的真正导出入口。 M4 — 交付保障 scripts/po2mbt 新增 --check 模式:比对已提交的 i18n_data.mbt 与 .po 生成结果,过期则非零退出。 CI test.yml 新增 moonbit-i18n-sync job 运行 scripts/po2mbt --check。 README.md 更新「已知移植差距 python-humanize#2」说明 i18n 已接入及同步流程。 验证 moon build / --target wasm-gc / --target native 三目标均编译通过(native 不再链接失败,确认 M2 生效)。 moon test --build-only 测试模块编译通过。 po2mbt --check 通过(已提交数据与 .po 同步)。
ordinal → pgettext 按位上下文查后缀(number.mbt:386):pgettext(digit.to_string() + " (male)", suffix),与 python-humanize 行为及 .po 目录结构一致。已验证 i18n_data.mbt 的 ctx_RuRU 含 ("2 (male)\x00nd", "ой")(\u{0} 分隔符与 lookup_context 匹配),故 activate("ru"); ordinal("2") → "2ой" 正确本地化;英文/未配置语言回退 "2nd"。
apnumber:原本就传原子词(gettext(words[n])),.po 中有对应条目,已正确工作,无需改。
fractional / scientific:该移植刻意采用数字分母/数字系数(如 "3/10"、"1.00 x 10⁶"),而 .po 目录无这些组合键,也无"分母转单词"映射。要真正本地化需引入单词映射表并改变输出格式——这会破坏既有 number_test.mbt 断言(期望 "3/10"、"10/3"、"1 1/4")。权衡后保留 gettext 路由(优雅回退英文),并在 README 既有的 i18n 说明中保持透明。这是设计取舍,非回归。
审查发现 python-humanize#2(CI 防护)
原 CI 只跑 po2mbt --check,未实际编译 MoonBit,无法捕获 native 链接回归(clock_native.mbt)。已新增 moonbit-build job(test.yml):安装 MoonBit 工具链,构建 wasm-gc 与 native 两个 target,success 依赖它。这能在 CI 端守住 gap-spec python-humanize#1.4。
验证
moon build(默认)、--target wasm-gc、--target native 三目标均编译通过(native 不再链接失败)。
moon test --build-only 测试模块编译通过;本地 moon test 的 0xc0000139 是 Windows wasm 运行时启动问题,与改动无关(建议 Linux/macOS CI 执行断言)。
唯一未能完全满足 spec §2.3 的是 fractional/scientific 的俄文本地化(受数字格式设计限制)。如需彻底支持,建议后续单开任务:引入分母/系数单词映射并同步更新 .po 与测试预期
Added intsuffix to humanize into just the symbol k, M, G, P, T, etc