# @discord/intl 中文文档

规范地址：https://npmcn.com/package/%40discord/intl/

版本：0\.33\.3
npm 元数据更新时间：2026-10-30T19:54:50.470Z
中文译文更新时间：2026-11-12T11:03:57.156Z
软件包许可：MIT

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

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

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

- 包体积（解压后）：196 kB，50 个文件
- 模块格式：CommonJS
- TypeScript 类型：包内自带
- 运行依赖：5 个
- peer 依赖：react \> 16
- 首次发布：2024-08-06T16:34:02.725Z
- 最新版本发布：2026-10-30T19:54:50.104Z
- 近 30 天下载量：182947（2026-10-13 至 2026-11-11，npm 官方下载统计）
- 已发布版本数：163（近 12 个月 18 个）

## 中文简介

在 React 项目中管理消息和翻译的客户端运行时间.

## 安装

```sh
npm install @discord/intl
```

也可以使用：`pnpm add @discord/intl`、`yarn add @discord/intl`、`bun add @discord/intl`

## README

# `@discord/intl`

重新定义国际化支持,由Discord创建,管理跨越多项目,多编程语言,多客户端平台的上百万条信息. 不和-intl支持将ICU MessageFormat语法与Markdown合并的扩展消息格式,使编写内容丰富,分层化的消息尽可能清晰而简洁.

这个项目的诞生是因为需要更灵活地进行翻译,希望拥有颗粒的所有权,以及需要重新设计,以跟上现代版本的翻译 `intl-messageformat` 还有其他能为系统提供动力的人.

## 使用量

你最可能只需要知道如何使用 `defineMessages` 用于编写新字符串和字符串模块。 一个消息 定义文件 _必须_ 有扩展名 `.messages.js`,以及 _必须_ 有默认的调用导出 `defineMessages` 内线,像这样:

```typescript
// Import the defineMessages magic function from the package.
import { defineMessages } from '@discord/intl';

/**
 * Meta information about the strings contained in this file. Each string will
 * be tagged with this information by default, and it will be sent along to
 * translators to help provide context, categorization, and some special
 * features like hiding "secret" strings that shouldn't be bundled until a
 * specific release date.
 *
 * Future additions would be able to specify visual context for each string
 * (e.g. a screenshot image where the string is used) and more.
 */
export const meta = {
  project: 'custom-status',
  secret: true,
  translate: true,
};

/**
 * Messages are "defined" by creating a default export with `defineMessages`.
 * This function provides the typeguards for the shape of each message, and
 * ensures a consistent format for the external tooling to rely on when finding
 * all messages in the codebase.
 *
 * This _must_ be defined inline as a default export, and will be transformed
 * by bundlers both in development and production builds.
 */
export default defineMessages({
  HELLO_WORLD: {
    defaultMessage: 'Hello, world!',
    description: 'The standard greeting for new computers.',
  },
});
```

## 发展

这个项目与 `intl-cli`数字 :

```shell
# Compile the TypeScript source to distributable JavaScript once
pnpm intl-cli runtime build
# For development, run in watch mode to compile changes on the fly
pnpm intl-cli rt watch
```

## 常见问题

### @discord/intl 是什么？

在 React 项目中管理消息和翻译的客户端运行时间\.

### 如何安装 @discord/intl？

在项目目录运行 npm install @discord/intl，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：react（\> 16）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。

### @discord/intl 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @discord/intl 支持 ESM 还是 CommonJS？

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

### @discord/intl 可以商用吗？

@discord/intl 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @discord/intl 的下载量有多少？

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

### @discord/intl 还在维护吗？

最新版本 0\.33\.3 发布于 2026/10/31（12 天前）；至今共发布 163 个版本，其中过去 12 个月发布了 18 个；首次发布于 2024/08/07。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

