【发布时间】:2018-04-29 02:59:48
【问题描述】:
我想根据count参数创建一个可以是单数或复数的句子:
# When count is 1
"This profile still contains 1 post"
# When count is 2
"This profile still contains 2 posts"
使用 Rails i18n 机制,我相信我必须嵌入 Ruby 代码才能获得“post”一词的正确复数形式。我正在尝试像这样构建它,但它不起作用:
# config/locales/en.yml
en:
message: "This profile still contains %{count} <%= Post.model_name.human(count: count).lowercase %>"
# Output of I18n.translate(:message, count: 2)
"This profile still contains 2 <%= Post.model_name.human(count: count).lowercase %>"
我已经尝试过<%= %>、%{ }、#{ } 和{{ }},但都失败了。
是否可以在 i18n 文件中嵌入 Ruby 代码?怎么样?
【问题讨论】:
标签: ruby-on-rails internationalization