Skip to content

Instantly share code, notes, and snippets.

@kyleslattery
Last active August 29, 2015 13:59
Show Gist options
  • Save kyleslattery/10766726 to your computer and use it in GitHub Desktop.
Save kyleslattery/10766726 to your computer and use it in GitHub Desktop.
Pluralize Helper for Ember
/*
{{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