PO/POT catalog checking for MoonBit, with format and HTML/XML contracts, cross-file consistency, and bounded plural analysis.
moon build --target js --release
node cli.mjs check examples/zh_CN.po --template examples/messages.pot --strict
node cli.mjs examples/project-quality/valid --recursive --markup html --consistency --strict --jsonnode cli.mjs check examples/broken.po --json
node cli.mjs inspect examples/zh_CN.po --json
node cli.mjs stats examples/zh_CN.po --json
node cli.mjs plural 'nplurals=2; plural=(n!=1);'
node cli.mjs rulesmoon build --target js --release
node scripts/package.mjs| 功能 | 本版本行为 |
|---|---|
| PO/POT 解析 | UTF-8、BOM、CRLF、多行字符串、字节转义、上下文、注释、引用、flags、obsolete |
| 源位置 | 文件名、条目索引、从 1 开始的行列;字符串续行纳入范围;end 为排他位置 |
| 目录与 metadata | 重复 context/msgid、缺失字段、头字段、charset、日期、空翻译、fuzzy、NUL、换行边界 |
| 格式合同 | 显式 c-format、python-format、python-brace-format 的参数身份和类型;C 参数序号、星号宽度精度;Python 命名字段 |
| HTML/XML 标记 | 显式选择片段模式;配对与嵌套、祖先关系、数量、属性存在与受保护值;允许同级子树、属性顺序及可翻译值变化 |
| 跨文件项目检查 | 按语言/上下文/源文建索引,报告译文、复数源文和格式标记冲突,提供双方位置;可选逆向同译文审阅 |
| 复数 | 受限语法解析、短路求值、除零与整数溢出、索引范围、翻译槽位完整性、有限区间覆盖 |
| POT 对比 | 精确匹配 context/msgid,报告缺失、多余、plural 来源变化、format flags 变化 |
| 配置 | 合法性校验、空翻译/fuzzy 严重性、严格模式、资源限制;部分审阅规则可关闭或改级 |
| 输出 | 文本、版本 1 JSON、目录结构、按 context 和源文件统计的翻译工作量 |
| 规范化 | 输出规范 PO 文本,保留条目内注释及 decoded 字符串,不修复翻译含义 |
node cli.mjs check examples/broken.po --config examples/strict.json --json
node cli.mjs normalize examples/zh_CN.po --output normalized.polet catalog = @szs.parse_catalog(source, file="zh_CN.po")
let report = @szs.check_catalog(catalog)
let json = @szs.report_json(report)moon check --target all --deny-warn
moon test --target js --deny-warn
moon test --target wasm-gc --deny-warn
moon info
moon fmt --check
moon build --target js --release --deny-warn
node --test tests/integration.mjs
node scripts/count-source.mjspython -m pip install polib==1.2.0
node scripts/fetch-fixtures.mjs
python tests/oracle.py tests/external/moonbit-docs-0.po tests/external/moonbit-docs-1.po
# 安装 GNU gettext 后,可添加 --gnu 比较正常/异常样例的结果pub(all) struct Catalog {
file : String
entries : Array[Entry]
diagnostics : Array[Diagnostic]
} derive(Debug)pub(all) struct CatalogHeader {
fields : Array[HeaderField]
diagnostics : Array[Diagnostic]
} derive(Debug)pub(all) struct ConsistencyOptions {
enabled : Bool
ignore_context : Bool
inverse : Bool
max_entries : Int
} derive(Debug)pub(all) struct FormatContract {
arguments : Array[FormatArgument]
style : String
} derive(Eq, Debug)pub(all) enum PluralExpr {
Constant(Int)
Count
Unary(String, PluralExpr)
Binary(String, PluralExpr, PluralExpr)
Conditional(PluralExpr, PluralExpr, PluralExpr)
} derive(Eq, Debug)pub(all) struct PluralRule {
nplurals : Int
expression : String
tree : PluralExpr
} derive(Eq, Debug)pub(all) struct ProjectFinding {
file_index : Int
diagnostic : Diagnostic
related_file : String?
related_span : Span?
related_entry : Int?
} derive(Debug)pub(all) struct ProjectPolicy {
policy : Policy
markup : MarkupOptions
consistency : ConsistencyOptions
} derive(Debug)pub(all) struct ProjectReport {
reports : Array[Report]
findings : Array[ProjectFinding]
exit_code : Int
} derive(Debug)pub(all) struct Report {
catalog : Catalog
diagnostics : Array[Diagnostic]
stats : Statistics
exit_code : Int
plural_checked_through : Int?
} derive(Debug)fn check_consistency(catalogs : Array[Catalog], options? : ConsistencyOptions) -> Array[ProjectFinding]fn dispatch(request : String) -> Stringfn evaluate_plural(expression : PluralExpr, n : Int, budget? : Int, maximum_depth? : Int) -> Result[Int, String]fn plural_coverage(rule : PluralRule, maximum? : Int, budget? : Int, maximum_depth? : Int) -> Result[PluralCoverage, String]fn quote_po(text : String) -> Stringfn validate_header(catalog : Catalog, header : CatalogHeader, template? : Bool) -> Array[Diagnostic]Install
Download zipPO/POT catalog checking for MoonBit, with format and HTML/XML contracts, cross-file consistency, and bounded plural analysis.