Rails i18n API Yaml 翻译文件中复数形式的示例
有人可以提供一个关于如何在 Rails i18n API 的 Yaml 翻译文件中使用复数形式的示例吗?基本上,这是从基于 gettext 的应用程序迁移到 Rails。
Rails 中 a18n 的复数形式记录在此处 http://guides.rubyonrails.org/i18n.html#多元化,但细节有限。
举例来说,我从一个使用复数形式的 gettext .po 文件中获得了这个示例:
msgid "found %d fatal error"
msgid_plural "found %d fatal errors"
msgstr[0] "s'ha trobat %d error fatal"
msgstr[1] "s'han trobat %d errors fatals"
How would that Look in a .yml file for the Rails i18n API。据我所知,Rails i18n 使用唯一的 id 键而不是消息本身作为翻译键 - 所以可以说上述复数消息的键是found_x_fatal_error。
另一件事是复数形式选择公式,它在 .yml 文件中的位置以及它的外观如何 - 例如,我们从 gettext .po 文件头中获得了这个选择公式:
Plural-Forms: nplurals=2; plural=n == 1 ? 0 : 1;
它在 YAML 文件中的外观如何。
Can someone please provide an example on how to use plural forms in a Yaml translation file for Rails i18n API. Basically this is about moving from a gettext based app to Rails.
Plural forms for a18n in Rails is documented here http://guides.rubyonrails.org/i18n.html#pluralization but with limited detail.
Say for example I have this sample from a gettext .po file that uses plural forms:
msgid "found %d fatal error"
msgid_plural "found %d fatal errors"
msgstr[0] "s'ha trobat %d error fatal"
msgstr[1] "s'han trobat %d errors fatals"
How would that look in a .yml file for the Rails i18n API. I understand that Rails i18n uses unique id keys rather than the messages themselves for translation keys - so lets say the key for the above plural messages is found_x_fatal_error.
The other thing is the plural forms selection formula, where does it go in the .yml file and how does it look - say for example we have this selection formula from a gettext .po file header:
Plural-Forms: nplurals=2; plural=n == 1 ? 0 : 1;
How would it look in the YAML file.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以配置更多选项:
根据 I18n 的版本,yml 文件中的值将是 {{count}} 或 %{count}。更多解释可以在这里找到:
http://guides.rubyonrails.org/i18n.html#pluralization
You can configure more options:
Depending on the version of I18n it will be {{count}} or %{count} in the yml file. More explanation can be found here:
http://guides.rubyonrails.org/i18n.html#pluralization