Module: Babelfish::Phrase::Pluralizer
- Defined in:
- lib/babelfish/phrase/pluralizer.rb
Overview
Babelfish pluralizer.
Class Method Summary collapse
Instance Method Summary collapse
-
#cs ⇒ Object
Czech, Slovak.
Class Method Details
.add(locales, rule) ⇒ Object
9 10 11 12 13 |
# File 'lib/babelfish/phrase/pluralizer.rb', line 9 def self.add( locales, rule ) locales = [ locales ] unless locales.kind_of?(Array) locales.each { |locale| @rules[locale] = rule } end |
.find_rule(locale) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/babelfish/phrase/pluralizer.rb', line 15 def self.find_rule( locale ) return @rules[locale] if @rules.has_key?(locale) locale = @rules.keys.find do |loc| /^#{Regexp.escape(loc)}[\-_]/.match(locale) ? loc : nil end locale = 'en' if locale.nil? return @rules[locale] end |
.is_int(input) ⇒ Object
26 27 28 |
# File 'lib/babelfish/phrase/pluralizer.rb', line 26 def self.is_int( input ) return (0 == input % 1) end |
Instance Method Details
#cs ⇒ Object
Czech, Slovak
260 261 262 263 264 265 266 267 268 269 270 271 272 273 |
# File 'lib/babelfish/phrase/pluralizer.rb', line 260 add(['cs', 'sk'], lambda { |n| # one → n is 1 if n == 1 return 0 end # few → n in 2..4 if n == 2 || n == 3 || n == 4 return 1 end # other return 2 }) |