]> git.openstreetmap.org Git - rails.git/commitdiff
Add russian pluralization logic, based on description in the russion
authorTom Hughes <tom@compton.nu>
Tue, 3 Nov 2009 09:22:23 +0000 (09:22 +0000)
committerTom Hughes <tom@compton.nu>
Tue, 3 Nov 2009 09:22:23 +0000 (09:22 +0000)
plugin here:

http://github.com/yaroslav/russian/blob/master/lib/russian/backend/advanced.rb

Also simplify the other pluralizers by defaulting to :other when a
specific subkey is not found.

Closes #2412.

vendor/plugins/globalize2/lib/globalize/backend/pluralizing.rb

index 753711d0b6ace1ef92bfc0bbd69ed11282099369..9dd9bb6672f374ec363a09f2975ba52769b0ae47 100644 (file)
@@ -7,6 +7,7 @@ module Globalize
         return entry unless entry.is_a?(Hash) and count
         key = :zero if count == 0 && entry.has_key?(:zero)
         key ||= pluralizer(locale).call(count, entry)
+        key = :other unless entry.has_key?(key)
         raise InvalidPluralizationData.new(entry, count) unless entry.has_key?(key)
         translation entry[key], :plural_key => key
       end
@@ -28,15 +29,26 @@ module Globalize
           @pluralizers ||= {
             :en => lambda { |count, entry|
               case count
-                when 1 then entry.has_key?(:one) ? :one : :other
+                when 1 then :one
                 else :other
               end
             },
+            :ru => lambda { |count, entry|
+              case count % 100
+                when 11,12,13,14 then :many
+                else case count % 10
+                       when 1 then :one
+                       when 2,3,4 then :few
+                       when 5,6,7,8,9,0 then :many
+                       else :other
+                     end
+              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
+                when 1 then :one
+                when 2 then :two
+                when 3,4 then :few
                 else :other
               end
             }