Skip to content

Instantly share code, notes, and snippets.

@nicolasblanco
Created October 7, 2010 14:30
Show Gist options
  • Save nicolasblanco/615174 to your computer and use it in GitHub Desktop.
Save nicolasblanco/615174 to your computer and use it in GitHub Desktop.
# Pluralize helper for French language.
#
# Because French pluralization has special rules :
# Example :
# pluralize(0, "degré") # => "0 degré"
# pluralize(1, "degré") # => "1 degré"
# pluralize(2, "degré") # => "2 degrés"
# pluralize(0.5, "degré") # => "0.5 degré"
# pluralize(1.9, "degré") # => "1.9 degré"
# pluralize(-1.9, "degré") # => "-1.9 degré"
# pluralize(-2, "degré") # => "-2 degrés"
#
# Options :
# :without_count : if you don't want to output the count (only the word),
# :plural : to use a custom plural.
#
def pluralize(count, singular, options = {})
"".tap do |result|
result << "#{count || 0} " unless options[:without_count]
result << (count.to_i > -2 && count.to_i < 2 ? singular : (options[:plural] || singular.pluralize)).to_s
end
end
@afranke
Copy link

afranke commented Nov 8, 2010

Ok, nevermind then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment