2010-12-05 8 views
5

私はロケール固有の複数化ルールをI18n & Railsに実装しようとしていますが、運がないです。ここで私がやっているものです:あなたが見ることができるように、私は強制的にしようとしているカスタムレールI18nロケールPluralizationヘルプ

# in config/initializers/locale.rb 
I18n::Backend::Simple.send(:include, I18n::Backend::Pluralization) 
{ 
    # Force Use of :few key 
    :ru => {:i18n => {:plural => {:rule => lambda { |n| :few}}}} 
} 

# in config/locales/ru.yml 
ru: 
    user: 
    one: One User 
    few: Few Users 
    many: Many Users 
    other: Other Users 

# Testing 
script/console 
>> I18n.locale = :ru ; I18n.t("user", :count => 20) 
=> "Other Users" 

:いくつかのキーを、(それは「少数のユーザー」を返す必要があります)この一顧pluralizerが動作する場合、単に確認するために.. .but何サイコロ:(

ここでは、私が実行している環境ません:

  • のRails 2.3.8
  • 国際化0.5.0宝石

どんなアイデア?

答えて

5

あなたの問題を再現しようとしましたが、同じ問題がありました。複数化ルールをロケールファイルに移動して正常に動作しました。

正規のYAMLが何らかの理由で自分のラムダを気に入らなかったように、ロケールファイルをRubyスタイルに切り替えました。

# config/initializers/locale.rb 
I18n::Backend::Simple.send(:include, I18n::Backend::Pluralization) 

# config/locales/ru.rb 
{ 
    :ru => { 
    :user => { 
     :one => "One User", 
     :few => "Few Users", 
     :many => "Many Users", 
     :other => "Other Users" 
    }, 
    :i18n => { 
     :plural => { 
     :rule => lambda { |n| :few } 
     } 
    } 
    } 
} 

# Testing 
$ script/console 
    Loading development environment (Rails 2.3.8) 
    >> I18n.locale = :ru; I18n.t("user", :count => 20) #=> "Few Users" 

があることを試してみると、それは甘い

+0

に役立ちますかどうかを確認することがあります。それはうまくいった。ありがとう、相棒! – dhulihan

関連する問題