Class Index [+]

Quicksearch

I18n::Backend::Pluralization

Public Instance Methods

pluralize(locale, entry, count) click to toggle source

Overwrites the Base backend translate method so that it will check the translation meta data space (:i18n) for a locale specific pluralization rule and use it to pluralize the given entry. I.e. the library expects pluralization rules to be stored at I18n.t(:’i18n.plural.rule’)

Pluralization rules are expected to respond to # and return a pluralization key. Valid keys depend on the translation data hash (entry) but it is generally recommended to follow CLDR’s style, i.e., return one of the keys :zero, :one, :few, :many, :other.

The :zero key is always picked directly when count equals 0 AND the translation data has the key :zero. This way translators are free to either pick a special :zero translation even for languages where the pluralizer does not return a :zero key.

    # File lib/i18n/backend/pluralization.rb, line 31
31:       def pluralize(locale, entry, count)
32:         return entry unless entry.is_a?(Hash) and count
33: 
34:         pluralizer = pluralizer(locale)
35:         if pluralizer.respond_to?(:call)
36:           key = count == 0 && entry.has_key?(:zero) ? :zero : pluralizer.call(count)
37:           raise InvalidPluralizationData.new(entry, count) unless entry.has_key?(key)
38:           entry[key]
39:         else
40:           super
41:         end
42:       end

Protected Instance Methods

pluralizer(locale) click to toggle source
    # File lib/i18n/backend/pluralization.rb, line 50
50:         def pluralizer(locale)
51:           pluralizers[locale] ||= I18n.t(:'i18n.plural.rule', :locale => locale, :resolve => false)
52:         end
pluralizers() click to toggle source
    # File lib/i18n/backend/pluralization.rb, line 46
46:         def pluralizers
47:           @pluralizers ||= {}
48:         end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.