@discord/intl

中文文档
0.33.3发布于 2026/10/31MITTypeScriptCommonJS构建来源已验证近 30 天下载 18.3万

Client runtime for managing messages and translations in a React project.

原始使用文档

@discord/intl

Redefined internationalization support, created by Discord to manage millions of messages across multiple projects, multiple programming languages, and multiple client platforms. discord-intl supports an expanded message format that combines ICU MessageFormat syntax with Markdown to make authoring rich, stylized messages as clear and concise as possible.

This project was born out of a need for more flexibility with our translations, a desire for granular ownership, and a need to refactor to keep up with modern versions of intl-messageformat and others that power the system.

Usage

You most likely only need to know about how to use defineMessages to write new strings and string modules. A message definition file must have the extension .messages.js, and must have a default export that calls defineMessages inline, like this:

// 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.',
  },
});

Development

This project is managed with the intl-cli:

# 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 共发布 163 个版本,首次发布于 2024/08/07;过去 12 个月发布了 18 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.33.3latest2026/10/3112 天前
0.33.22026/10/2320 天前
0.33.12026/10/061 个月前
0.32.02026/09/032 个月前
0.31.02026/08/202 个月前
0.30.02026/08/142 个月前

其他发布通道:canary → 0.28.0-canary.eb67948。

关于 @discord/intl 的常见问题

@discord/intl 是什么?

Client runtime for managing messages and translations in a React project.

如何安装 @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 和提交记录判断。