Last active
August 29, 2015 13:59
-
-
Save kyleslattery/10766726 to your computer and use it in GitHub Desktop.
Pluralize Helper for Ember
This file contains hidden or 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 someCount "person" "people"}} | |
When someCount == 1 => "1 person" | |
When someCount != 1 => "0 people", "10 people" | |
If the final argument is omitted, the plural is made by | |
appending an "s" to the second argument | |
*/ | |
Ember.Handlebars.registerBoundHelper('pluralize', function(count, singular, plural) { | |
if (arguments.length < 3) return ""; | |
if (arguments.length == 3) { | |
// didn't specify a plural, so let's make it | |
plural = singular + "s"; | |
} | |
if (count == 1) return "1 " + singular; | |
else return count + " " + plural; | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment