1

I am trying to translate some counter of items according to the grammar of the language. I faced with an issue that doc says about plural forms and they are different for each language. I expected that rules are already inside I18n and what I need to do is just fill translations. But when I read the code of pluralize method at i18n/backend/base.rb

   def pluralize(locale, entry, count)
      return entry unless entry.is_a?(Hash) && count

      key = :zero if count == 0 && entry.has_key?(:zero)
      key ||= count == 1 ? :one : :other
      raise InvalidPluralizationData.new(entry, count) unless entry.has_key?(key)
      entry[key]
    end

I found that it supports only en. For example I am working now on arabic translation.

I18n.backend.store_translations :ar, path: { one: 'one', two: 'two', other: 'other', many: 'many', few: 'few'}

Here I filled translation backend and I expect that if I pass count option 11 then I receive :many translation as specified by the language plural rules.

I18n.t :path, count: 11, locale: :ar #should return 'many'

Do I need to specify those rules myself? Then where? Or do I need swizzle something?

vlad.grb
  • 339
  • 4
  • 16
  • Possible duplicate of [i18n Pluralization](http://stackoverflow.com/questions/6166064/i18n-pluralization) – rene Jan 14 '17 at 16:08

2 Answers2

0

You can create your own rules, for this, you can create the file: config/initializers/inflections.rb and adapt this example to your reality:

ActiveSupport::Inflector.inflections(:en) do |inflect|
  inflect.plural /^(ox)$/i, '\1\2en'
  inflect.singular /^(ox)en/i, '\1'

  inflect.irregular 'octopus', 'octopi'

  inflect.uncountable 'equipment'
end

Take a look in the documentation: Inflections

augustocbx
  • 762
  • 8
  • 8
0

This answer solved my issue. I need enable loading mode for custom plural rules and then specify keyword for each case.

Community
  • 1
  • 1
vlad.grb
  • 339
  • 4
  • 16