我想在Rails 3.0.9中使用t('errors', :count => 2),并希望它返回"2 napaki“,这是一种特殊的复数形式。
我已经创建了locales/sl.yml,并具有以下代码:
sl:
error:
one: %{count} napaka
two: %{count} napaki
other: %{count} napak但这似乎行不通。
发布于 2011-08-04 18:00:16
确保将翻译放在config/locales/sl.yml中。您还需要创建一个config/locales/plarials.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,...
您也可以使用have a look at this gist,它完全按照您的要求进行操作。
https://stackoverflow.com/questions/6939372
复制相似问题