Created
October 7, 2010 14:30
-
-
Save nicolasblanco/615174 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ok, nevermind then.