確保你把你的翻譯放在config/locales/sl.yml中。您還需要創建一個文件的config /區域設置/ 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,...
你也可以有have a look at this gist這正是你所要求的。
它的工作原理。非常感謝! – pr0factor87