消息格式
翻译者准则
在 Discourse 中,所有 Message Format 字符串都有一个以 "_MF" 结尾的键。Crowdin 编辑器具有预览功能,可以让你试验各种值,这对检查你的翻译非常有帮助。

重要: 如果你的语言使用 "one" 和 "other" 以外的形式,你需要修改翻译的复数形式。你可以在 { FOO, plural, ... } 块内添加或移除形式,以使其适用于你的语言。当你的翻译有问题时,Crowdin 编辑器中的预览会显示 "语法错误"。
可用的复数形式有:
- 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, }); -
:loudspeaker: 建议: 如果可能,请将复杂参数用作消息的最外层结构,并在其子消息中写入完整句子。如果你嵌套了 select 和 plural 参数,请将 select 参数(带有其固定的选项集)放在外层,并将 plural 参数(最好最多只有一个)嵌套在内层。查看 https://unicode-org.github.io/icu/userguide/format_parse/messages/
-
让它们易于阅读,查看 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.
工具和更多信息
-
https://format-message.github.io/icu-message-format-for-translators/editor.html 让你可以在 Crowdin 编辑器出现问题时测试 Message Format 字符串。请禁用 "解析简单的 xml/html 标签" 选项,否则你可能会看到错误消息。
-
https://format-message.github.io/icu-message-format-for-translators/
谢谢你的反馈!