moon add LP-XXX/moonmoimport {
"LP-XXX/moonmo",
}fn menu_label(bytes : Bytes) -> String raise @moonmo.GettextError {
let cat = @moonmo.Catalog::from_bytes(bytes)
cat.pgettext("menu", "Open")
}moon run --target wasm-gc examples/todo # 待办清单,依次显示英、中、法
moon run --target wasm-gc examples/scoreboard # 足球计分牌,英、法、捷克语
moon run --target wasm-gc examples/duration # 时长换算,复数形式随数量变化
moon run --target native examples/lookup -- fixtures/mo/fr_le.mo Open --context menu| 入口 | 调用约定 |
|---|---|
| Catalog::from_bytes / Catalog::empty | 从 MO 构造只读目录,或创建用于源文回退的空目录 |
| gettext / pgettext | 按消息 ID,或按上下文与消息 ID 查询,缺失时返回源文 |
| ngettext / npgettext | 传入单数源文、复数源文和 UInt64 数量,上下文版本另传上下文 |
| try_gettext / try_pgettext | 直接返回 String?,可区分未收录和空译文 |
| try_ngettext_checked / try_npgettext_checked | 只需单数键和数量,可加上下文;求值失败或索引不可用时抛出具体错误 |
| metadata() / plural_rule() / len() | 查看结构化头、编译后的复数规则或目录条目数。条目数包含已存储的元数据头 |
| mo.parse_mo / plural.parse_expr / PluralRule::parse | 单独检查 MO 布局、解析表达式或解析整条复数声明 |
| make_translator / make_switchable_translator | 将固定目录或可切换的目录引用接到 moonpug 的 translate 回调 |
flowchart LR
fs["fs · 文件 → Bytes"] --> catalog
pug["adapters/moonpug · 翻译回调"] --> catalog
catalog["Catalog · 查找与回退"] --> mo["mo · 二进制校验与元数据"]
catalog --> plural["plural · 词法、语法与求值"]moon test --target native
moon test --target wasm
moon test --target wasm-gc
moon test --target js
moon check --deny-warn
moon fmt --check.\scripts\verify_all.ps1 # Windowsbash scripts/verify_all.sh # Linux / macOS / Git Bashpub suberror GettextError {
Mo(MoError)
Plural(PluralError)
PluralFormOutOfRange(msgid~ : String, index~ : Int, available_forms~ : Int, nplurals~ : Int)
} derive(Eq, Debug)impl Show for GettextErrorpub struct Catalog {
// private fields
}fn Catalog::try_ngettext_checked(self : Catalog, msgid : String, n : UInt64) -> String? raise GettextErrorfn Catalog::try_npgettext_checked(self : Catalog, msgctxt : String, msgid : String, n : UInt64) -> String? raise GettextErrorimpl Show for CatalogMetadata