1

I'd like to use t('errors', :count => 2) with slovenian translation in Rails 3.0.9 and want it to return "2 napaki" which is a special plural form for slovene language.

I have created locales/sl.yml and have this code:

sl:
  error:
    one: %{count} napaka
    two: %{count} napaki
    other: %{count} napak

But this doesn't seem to work.

4

1 回答 1

1

确保将翻译放在 config/locales/sl.yml 中。您还需要创建一个文件 config/locales/plurals.rb 并将以下代码放入其中:

# More rules in this file: https://github.com/svenfuchs/i18n/blob/master/test/test_data/locales/plurals.rb
I18n::Backend::Simple.send(:include, I18n::Backend::Pluralization)
{
  :'sl' => { :i18n => { :plural => { :rule => lambda { |n| [1].include?(n % 100) && ![11].include?(n % 100) ? :one : [2].include?(n % 100) && ![12].include?(n % 100) ? :two : [3, 4].include?(n % 100) && ![13, 14].include?(n % 100) ? :few : :other }}}}
}

在你的 application.rb 中确保你设置了默认的语言环境:

class Application < Rails::Application
  ...
  config.i18n.default_locale = :sl
  ...
end

确保在进行这些更改后重新启动服务器。此外:one, :two, :other,您还可以:few使用 3、4、...等数字

你也可以看看这个要点,它完全符合你的要求。

于 2011-08-04T10:00:15.950 回答