For AI agents: the complete documentation index is available at /tc39-atlas/llms.txt, the full documentation bundle is available at /tc39-atlas/llms-full.txt, and this page is available as Markdown at /tc39-atlas/proposals/stage/4/proposal-intl-plural-rules.md.
  • 简体中文
  • Intl.PluralRules S4

    提案概览
    提案速览

    该提案引入了一个新的 API Intl.PluralRules,用于根据 locale 和类型(基数或序数)为给定数字选择适当的复数类别。该提案还支持序数复数,并规定了 pluralCategories 的解析。

    Note

    以下 README 来自上游仓库,其中的阶段或状态标注可能滞后;当前信息以提案概览为准。

    Intl.PluralRules API 规范 [草稿]

    状态

    当前阶段:

    • 第 4 阶段

    实现进度:

    解释器:

    规范文本:

    作者

    • Caridy Patiño (@caridy)
    • Eric Ferraiuolo (@ericf)
    • Alex Sexton (@SlexAxton)

    审阅者

    • Daniel Ehrenberg (@littledan)
    • Stefan Penner (@stefanpenner)

    参考信息

    本提案基于 LDML 规范,C.11 语言复数规则:

    先前实现

    • Java: Class PluralRules

    用法

    let o = new Intl.PluralRules("en", {
        type: "cardinal" // default type
    });
    console.log(o.select(0)); // "other"
    console.log(o.select(1)); // "one"
    console.log(o.select(2)); // "other"

    还包含对序数词的支持:

    let o = new Intl.PluralRules("en", {
        type: "ordinal"
    });
    console.log(o.select(21)); // "one"
    console.log(o.select(22)); // "two"
    console.log(o.select(23)); // "few"
    console.log(o.select(24)); // "other"

    待办事项

    • new Intl.PluralRules("en").format(1.02); 应该产生 "other"
    • 对 Intl.PluralRules 进行命名讨论
    • 规范 pluralCategories 的解析

    渲染规范

    npm install
    npm run build
    open index.html

    反向链接