]> git.openstreetmap.org Git - rails.git/blob - vendor/plugins/globalize2/lib/globalize/backend/pluralizing.rb
Allow the "remember me" label to wrap when showing OpenID URL field
[rails.git] / vendor / plugins / globalize2 / lib / globalize / backend / pluralizing.rb
1 require 'i18n/backend/simple'
2
3 module Globalize
4   module Backend
5     class Pluralizing < I18n::Backend::Simple
6       def pluralize(locale, entry, count)
7         return entry unless entry.is_a?(Hash) and count
8         key = :zero if count == 0 && entry.has_key?(:zero)
9         key ||= pluralizer(locale).call(count, entry)
10         key = :other unless entry.has_key?(key)
11         raise InvalidPluralizationData.new(entry, count) unless entry.has_key?(key)
12         translation entry[key], :plural_key => key
13       end
14
15       def add_pluralizer(locale, pluralizer)
16         pluralizers[locale.to_sym] = pluralizer
17       end
18
19       def pluralizer(locale)
20         pluralizers[locale.to_sym] || default_pluralizer
21       end
22
23       protected
24         def default_pluralizer
25           pluralizers[:en]
26         end
27
28         def pluralizers
29           @pluralizers ||= {
30             :en => lambda { |count, entry|
31               case count
32                 when 1 then :one
33                 else :other
34               end
35             },
36             :ar => lambda { |count, entry|
37               case count
38                 when 1 then :one
39                 when 2 then :two
40                 else case count % 100
41                        when 3..10 then :few
42                        when 11..99 then :many
43                        else :other
44                      end
45               end
46             },
47             :ru => lambda { |count, entry|
48               case count % 100
49                 when 11,12,13,14 then :many
50                 else case count % 10
51                        when 1 then :one
52                        when 2,3,4 then :few
53                        when 5,6,7,8,9,0 then :many
54                        else :other
55                      end
56               end
57             },
58             :sl => lambda { |count, entry|
59               case count % 100
60                 when 1 then :one
61                 when 2 then :two
62                 when 3,4 then :few
63                 else :other
64               end
65             }
66           }
67         end
68
69         # Overwrite this method to return something other than a String
70         def translation(string, attributes)
71           string
72         end
73     end
74   end
75 end