@discord/intl
重新定义国际化支持,由Discord创建,管理跨越多项目,多编程语言,多客户端平台的上百万条信息. 不和-intl支持将ICU MessageFormat语法与Markdown合并的扩展消息格式,使编写内容丰富,分层化的消息尽可能清晰而简洁.
这个项目的诞生是因为需要更灵活地进行翻译,希望拥有颗粒的所有权,以及需要重新设计,以跟上现代版本的翻译 intl-messageformat 还有其他能为系统提供动力的人.
使用量
你最可能只需要知道如何使用 defineMessages 用于编写新字符串和字符串模块。 一个消息
定义文件 必须 有扩展名 .messages.js,以及 必须 有默认的调用导出 defineMessages
内线,像这样:
// 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数字 :
# 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