# in config/initializers/locale.rbI18n::Backend::Simple.send(:include,I18n::Backend::Pluralization){ # Force Use of :few key :ru => {:i18n => {:plural => {:rule => lambda { |n| :few}}}}}# in config/locales/ru.ymlru: user: one: One User few: Few Users many: Many Users other: Other Users# Testingscript/console>> I18n.locale = :ru ; I18n.t("user",:count => 20)=> "Other Users"
你可以看到,我试图强制:几个键(它应该返回“少数用户”),只是为了看看这个dang复数器是否会工作…但没有骰子:(
这是我正在运行的环境:
> Rails 2.3.8
> i18n 0.5.0宝石
有任何想法吗?
解决方法 尝试复制你的问题,并有同样的问题.将复数规则移动到语言环境文件中,并且运行正常.将语言环境文件切换到Ruby风格,因为常规的YAML似乎不喜欢我的lambda因某种原因.
# config/initializers/locale.rbI18n::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"
可能会尝试一下,看看它是否有帮助
总结以上是内存溢出为你收集整理的ruby-on-rails – 自定义Rails I18n Locale Pluralization帮助全部内容,希望文章能够帮你解决ruby-on-rails – 自定义Rails I18n Locale Pluralization帮助所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)