@ember-intl/intl-messageformat-parser

中文文档
1.5.0发布于 2018/11/05BSD-3-ClauseCommonJS零依赖近 30 天下载 2.5万

通过 JavaScript 将 ICU 信件字符串分析为 AST .

此软件包已被标记为弃用

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

中文使用文档
文档目录6 节
  1. 概览
  2. 使用量
  3. 在浏览器中加载
  4. 在节点中装入
  5. 示例
  6. 许可证

输入信件格式解析器

参数 ICU 信件字符串 通过 JavaScript 输入 AST .

npm Version Build Status Dependency Status

概览

此软件包在 JavaScript 中执行解析器, 解析行业标准 ICU 信件字符串 ——用于国际化——成为AST. 生成的 AST 可以被编译器使用, 比如 intl-messageformat,用于向用户显示本地化格式字符串.

此解析器为 国家,用于 JavaScript 的解析器生成器。 这个解析器的执行灵感和来源于Alex Sexton的 messageformat.js 页面存档备份,存于互联网档案馆 项目。 与亚历克斯执行的区别是:

  • 这个项目是独立的.
  • 它作为ES6模块被编译为CommonJS和为浏览器所使用Bundle格式.
  • 生成的AST更能描述并使用递归结构.
  • AST 中使用的关键词与 ICU 信件" spec"相匹配.

使用量

在浏览器中加载

这个 dist/ 文件夹中包含此软件包的版本, 供浏览器使用, 可以这样加载和使用 :

<script src="intl-messageformat-parser/dist/parser.min.js"></script>
<script>
    IntlMessageFormatParser.parse('...');
</script>

在节点中装入

这个软件包也可以是 require()- 在节点:

var parser = require('intl-messageformat-parser');
parser.parse('...');

示例

考虑到这样的 ICU 信件字符串 :

On {takenDate, date, short} {name} took {numPhotos, plural,
    =0 {no photos.}
    =1 {one photo.}
    other {# photos.}
}
// Assume `msg` is the string above.
parser.parse(msg);

此解析器将生成此 AST :

{
    "type": "messageFormatPattern",
    "elements": [
        {
            "type": "messageTextElement",
            "value": "On "
        },
        {
            "type": "argumentElement",
            "id": "takenDate",
            "format": {
                "type": "dateFormat",
                "style": "short"
            }
        },
        {
            "type": "messageTextElement",
            "value": " "
        },
        {
            "type": "argumentElement",
            "id": "name",
            "format": null
        },
        {
            "type": "messageTextElement",
            "value": " took "
        },
        {
            "type": "argumentElement",
            "id": "numPhotos",
            "format": {
                "type": "pluralFormat",
                "offset": 0,
                "options": [
                    {
                        "type": "optionalFormatPattern",
                        "selector": "=0",
                        "value": {
                            "type": "messageFormatPattern",
                            "elements": [
                                {
                                    "type": "messageTextElement",
                                    "value": "no photos."
                                }
                            ]
                        }
                    },
                    {
                        "type": "optionalFormatPattern",
                        "selector": "=1",
                        "value": {
                            "type": "messageFormatPattern",
                            "elements": [
                                {
                                    "type": "messageTextElement",
                                    "value": "one photo."
                                }
                            ]
                        }
                    },
                    {
                        "type": "optionalFormatPattern",
                        "selector": "other",
                        "value": {
                            "type": "messageFormatPattern",
                            "elements": [
                                {
                                    "type": "messageTextElement",
                                    "value": "# photos."
                                }
                            ]
                        }
                    }
                ]
            }
        }
    ]
}

许可证

这个软件可以在雅虎下自由使用! BSD许可证. 见 自由文件 许可证文本和版权信息.

版本与发布记录

@ember-intl/intl-messageformat-parser 共发布 4 个版本,首次发布于 2017/08/24;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.5.0latest2018/11/058 年前
1.4.02018/10/098 年前
2.0.12017/08/249 年前
2.0.02017/08/249 年前

关于 @ember-intl/intl-messageformat-parser 的常见问题

@ember-intl/intl-messageformat-parser 是什么?

通过 JavaScript 将 ICU 信件字符串分析为 AST .注意:该包已被作者标记为弃用——Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

如何安装 @ember-intl/intl-messageformat-parser?

在项目目录运行 npm install @ember-intl/intl-messageformat-parser,或使用 pnpm add / yarn add / bun add。

@ember-intl/intl-messageformat-parser 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/ember-intl__intl-messageformat-parser 是否存在。

@ember-intl/intl-messageformat-parser 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@ember-intl/intl-messageformat-parser 可以商用吗?

@ember-intl/intl-messageformat-parser 使用 BSD-3-Clause 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。另外不得用原作者名义为衍生产品背书。以上为概括,不构成法律意见,请以许可原文为准。

@ember-intl/intl-messageformat-parser 的下载量有多少?

根据 npm 官方下载统计,@ember-intl/intl-messageformat-parser 在 2026/10/14 – 2026/11/12 这 30 天内被下载 25,130 次,日均约 838 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@ember-intl/intl-messageformat-parser 还在维护吗?

最新版本 1.5.0 发布于 2018/11/05(8 年前);至今共发布 4 个版本,其中过去 12 个月发布了 0 个;首次发布于 2017/08/24。作者已将其标记为弃用,新项目建议寻找替代方案。