From 6af3f93761f48920b619c2f352b0de90181e4a64 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Tue, 21 Jul 2009 20:23:07 +0000 Subject: [PATCH 1/1] 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. --- config/initializers/i18n.rb | 2 -- config/locales/sl.yml | 3 --- .../lib/globalize/backend/pluralizing.rb | 21 ++++++++++++++++--- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/config/initializers/i18n.rb b/config/initializers/i18n.rb index a061d873a..54a925e3c 100644 --- a/config/initializers/i18n.rb +++ b/config/initializers/i18n.rb @@ -2,5 +2,3 @@ require 'globalize/i18n/missing_translations_log_handler' I18n.missing_translations_logger = Logger.new("#{RAILS_ROOT}/log/missing_translations.log") I18n.exception_handler = :missing_translations_log_handler - -I18n.backend.add_pluralizer :sl, lambda { |c| c%100 == 1 ? :one : c%100 == 2 ? :two : (3..4).include?(c%100) ? :few : :other } diff --git a/config/locales/sl.yml b/config/locales/sl.yml index b30d2e3b5..2bcec4e69 100644 --- a/config/locales/sl.yml +++ b/config/locales/sl.yml @@ -210,9 +210,6 @@ sl: nodes: "Vozlišča:" part_of: "Del:" also_part_of: - one: "tudi del poti {{related_ways}}" - two: "tudi del poti {{related_ways}}" - few: "tudi del poti {{related_ways}}" other: "tudi del poti {{related_ways}}" way_history: way_history: "Zgodovina poti" diff --git a/vendor/plugins/globalize2/lib/globalize/backend/pluralizing.rb b/vendor/plugins/globalize2/lib/globalize/backend/pluralizing.rb index 80016f208..753711d0b 100644 --- a/vendor/plugins/globalize2/lib/globalize/backend/pluralizing.rb +++ b/vendor/plugins/globalize2/lib/globalize/backend/pluralizing.rb @@ -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 \ No newline at end of file +end -- 2.43.2