2011-08-04 27 views
1

我想在Rails 3.0.9中使用t('errors', :count => 2)與斯洛文尼亞語的翻譯,並希望它返回「2 napaki」,它是斯洛文尼亞語的一種特殊複數形式。Rails 3和斯洛文尼亞複數

我創造語言環境/ sl.yml和有這樣的代碼:

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

但這似乎並沒有工作。

回答

1

確保你把你的翻譯放在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這正是你所要求的。

+0

它的工作原理。非常感謝! – pr0factor87