Update the :en and :sl pluralizers to default to :other if a more

specific key does not exist. This then allows r16613 to be reverted
as there is no need to distinguish the cases. Fixes #2087.
This commit is contained in:
Tom Hughes 2009-07-21 20:23:07 +00:00
parent 78fd4588b8
commit 6af3f93761
3 changed files with 18 additions and 8 deletions

View file

@ -6,7 +6,7 @@ module Globalize
def pluralize(locale, entry, count)
return entry unless entry.is_a?(Hash) and count
key = :zero if count == 0 && entry.has_key?(:zero)
key ||= pluralizer(locale).call(count)
key ||= pluralizer(locale).call(count, entry)
raise InvalidPluralizationData.new(entry, count) unless entry.has_key?(key)
translation entry[key], :plural_key => key
end
@ -25,7 +25,22 @@ module Globalize
end
def pluralizers
@pluralizers ||= { :en => lambda{|n| n == 1 ? :one : :other } }
@pluralizers ||= {
:en => lambda { |count, entry|
case count
when 1 then entry.has_key?(:one) ? :one : :other
else :other
end
},
:sl => lambda { |count, entry|
case count % 100
when 1 then entry.has_key?(:one) ? :one : :other
when 2 then entry.has_key?(:two) ? :two : :other
when 3,4 then entry.has_key?(:few) ? :few : :other
else :other
end
}
}
end
# Overwrite this method to return something other than a String
@ -34,4 +49,4 @@ module Globalize
end
end
end
end
end