多元化无法正常运作

时间:2014-02-19 14:33:46

标签: ruby-on-rails ruby-on-rails-4

Rails 4.0.2

我无法正确地进行工作复数化。只有:zero:one:other有效。但我需要所有表单::zero:one:few:many:other

config/initializers文件夹文件pluralization.rb已创建:

变式1:

require "i18n/backend/pluralization"
I18n::Backend::Simple.send(:include, I18n::Backend::Pluralization)
{
:ru => { :i18n => { :plural => { :keys => [:one, :few, :many, :other], :rule => lambda { |n| n % 10 == 1 && n % 100 != 11 ? :one : [2, 3, 4].include?(n % 10) && ![12, 13, 14].include?(n % 100) ? :few : n % 10 == 0 || [5, 6, 7, 8, 9].include?(n % 10) || [11, 12, 13, 14].include?(n % 100) ? :many : :other } } } }
}

变式2:

require "i18n/backend/pluralization"
I18n::Backend::Simple.send(:include, I18n::Backend::Pluralization)

已创建config/locales文件ru.yml

ru:
  kids:
    zero: ru_zero
    one: ru_one
    few: ru_few
    many: ru_many
    other: ru_other

在application.rb中:

config.i18n.default_locale = :ru

测试代码:

0.upto 15 {|i|
  i.to_s + " "
  t(:kids, count: i)
}

输出:

0 ru_zero
1 ru_one
2 ru_other
3 ru_other
4 ru_other
5 ru_other
6 ru_other
7 ru_other
8 ru_other
9 ru_other
10 ru_other
11 ru_other
12 ru_other
13 ru_other
14 ru_other
15 ru_other

我很困惑。

0 个答案:

没有答案