Skip to content

Instantly share code, notes, and snippets.

@rusllonrails
Created February 18, 2014 10:17
Show Gist options
  • Save rusllonrails/9068136 to your computer and use it in GitHub Desktop.
Save rusllonrails/9068136 to your computer and use it in GitHub Desktop.
COFFEE SCRIPT PLURALIZE
app.pluralize = (num, variant1, variant2, variant3)->
plural =
if num % 10 == 1 && num % 100 != 11
0
else if num % 10 >= 2 && num % 10 <= 4 && (num % 100 < 10 || num % 100 >= 20)
1
else
2
switch plural
when 0 then variant1
when 1 then variant2
when 2 then variant3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment