译者指南
在 Discourse 中,所有 Message Format 字符串的键都以 “_MF” 结尾。Crowdin 编辑器提供了一个预览功能,允许您尝试不同的值,这对检查翻译非常有帮助。
重要提示: 如果您的语言使用除 “one” 和 “other” 以外的复数形式,您需要修改翻译中的复数形式。您可以添加或移除 { FOO, plural, ... } 块中的形式,以使其适用于您的语言。如果翻译存在问题,Crowdin 编辑器的预览中将显示“语法错误”(Syntax error)。
可用的复数形式包括:
- zero
- one
- two
- few
- many
- other(必需 — 通用复数形式 — 也用于不区分单数和复数形式的语言)
有时您可能会在英文源字符串中看到一个空的 =0 {} 块,这意味着该变量不能为 0。
开发者指南
Message Format 字符串目前仅可用于客户端翻译。当您的字符串包含多个数字或许多变量,从而导致大量的排列组合时,它们非常有用。
-
Message Format 字符串的键必须以 “_MF” 结尾
-
对于数字(
#将被替换为数字),请使用以下格式:{ variable_name, plural, one: {# singular text} other: {# plural text} } -
对于选择,请使用以下格式:
{ variable_name, select, foo: {This is foo} bar: {This is bar} baz: {This is baz} } -
在 JavaScript 中使用的示例如下:
I18n.messageFormat("key_MF", { variable1: "foo", variable2: 42, }); -
建议: 如果可能,请将复杂参数用作消息的最外层结构,并在其子消息中编写完整的句子。如果您有嵌套的 select 和 plural 参数,请将 select 参数(具有固定选项集)放在外部,并将 plural 参数(最好最多一个)嵌套在内部。参见 Formatting Messages | ICU Documentation -
确保它们可读 —— 请查看 client.en.yml 中的现有示例
错误示例There {currentTopics, plural, one {is <strong>#</strong> topic} other {are <strong>#</strong> topics}}. Visitors need more to read and reply to – we recommend at least { requiredTopics, plural, one {<strong>#</strong> topic} other {<strong>#</strong> topics}}. Only staff can see this message.
正确示例There { currentTopics, plural, one {is <strong>#</strong> topic} other {are <strong>#</strong> topics} }. Visitors need more to read and reply to – we recommend at least { requiredTopics, plural, one {<strong>#</strong> topic} other {<strong>#</strong> topics} }. Only staff can see this message.
工具和更多信息
-
如果 Crowdin 编辑器出现问题,Online ICU Message Editor 允许您测试 Message Format 字符串。请禁用“解析简单 xml/html 标签”(Parse simple xml/html tags)选项,否则您可能会看到错误消息。
本文档受版本控制 - 请在 github 上建议更改。
