# @ember-intl/intl-messageformat-parser 中文文档

规范地址：https://npmcn.com/package/%40ember-intl/intl-messageformat-parser/

版本：1\.5\.0
npm 元数据更新时间：2026-10-20T09:43:34.436Z
中文译文更新时间：2026-11-13T15:02:00.929Z
软件包许可：BSD-3-Clause

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40ember-intl/intl-messageformat-parser
原文对照：https://npmcn.com/package/%40ember-intl/intl-messageformat-parser/?lang=original
项目主页：https://github.com/yahoo/intl-messageformat-parser
源码仓库：https://github.com/yahoo/intl-messageformat-parser

弃用说明：Package no longer supported\. Contact Support at https://www\.npmjs\.com/support for more info\.

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：463 kB，12 个文件
- 模块格式：CommonJS
- TypeScript 类型：未声明
- 运行依赖：0 个
- 首次发布：2017-08-24T00:06:54.047Z
- 最新版本发布：2018-11-04T17:56:14.859Z
- 近 30 天下载量：25130（2026-10-14 至 2026-11-12，npm 官方下载统计）
- 已发布版本数：4（近 12 个月 0 个）

## 中文简介

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

## 安装

```sh
npm install @ember-intl/intl-messageformat-parser
```

也可以使用：`pnpm add @ember-intl/intl-messageformat-parser`、`yarn add @ember-intl/intl-messageformat-parser`、`bun add @ember-intl/intl-messageformat-parser`

## README

# 输入信件格式解析器

参数 [ICU 信件字符串](http://userguide.icu-project.org/formatparse/messages) 通过 JavaScript 输入 AST .

[![npm Version](https://img.shields.io/npm/v/intl-messageformat-parser.svg?style=flat-square)](https://www.npmjs.org/package/intl-messageformat-parser) [![Build Status](https://img.shields.io/travis/yahoo/intl-messageformat-parser.svg?style=flat-square)](https://travis-ci.org/yahoo/intl-messageformat-parser) [![Dependency Status](https://img.shields.io/david/yahoo/intl-messageformat-parser.svg?style=flat-square)](https://david-dm.org/yahoo/intl-messageformat-parser)

## 概览

此软件包在 JavaScript 中执行解析器, 解析行业标准 [ICU 信件字符串](http://userguide.icu-project.org/formatparse/messages) ——用于国际化——成为AST. 生成的 AST 可以被编译器使用, 比如 [`intl-messageformat`](https://github.com/yahoo/intl-messageformat),用于向用户显示本地化格式字符串.

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

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

## 使用量

### 在浏览器中加载

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

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

### 在节点中装入

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

```js
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.}
}
```

```js
// Assume `msg` is the string above.
parser.parse(msg);
```

此解析器将生成此 AST :

```json
{
    "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许可证. 见 [自由文件](https://github.com/yahoo/intl-messageformat-parser/blob/master/LICENSE) 许可证文本和版权信息.

## 常见问题

### @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。作者已将其标记为弃用，新项目建议寻找替代方案。

