【问题标题】:Rails 3 and Slovenian pluralizationRails 3 和斯洛文尼亚语多元化
【发布时间】:2011-10-19 20:13:25
【问题描述】:

我想在 Rails 3.0.9 中使用带有斯洛文尼亚语翻译的 t('errors', :count => 2),并希望它返回“2 napaki”,这是斯洛文尼亚语的特殊复数形式。

我已经创建了 locales/sl.yml 并拥有以下代码:

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

但这似乎不起作用。

【问题讨论】:

    标签: ruby-on-rails-3 localization pluralize


    【解决方案1】:

    确保将翻译放在 config/locales/sl.yml 中。您还需要创建一个文件 config/locales/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,这正是您所要求的。

    【讨论】:

      猜你喜欢
      • 2013-11-24
      • 2012-02-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多