Skip to content

Instantly share code, notes, and snippets.

@tomaskavalek
Created May 6, 2021 11:41
Show Gist options
  • Save tomaskavalek/3f513b3672d31fce61c050e0ed754a81 to your computer and use it in GitHub Desktop.
Save tomaskavalek/3f513b3672d31fce61c050e0ed754a81 to your computer and use it in GitHub Desktop.
JavaScript Plurals
// CZ
function plural(n)
{
return arguments[(n === 1) ? 1 : ((n >= 2 && n <= 4) ? 2 : 3)];
}
// Examples
plural(1, 'uživatel', 'uživatelé', 'uživatelů')
"uživatel"
plural(2, 'uživatel', 'uživatelé', 'uživatelů')
"uživatelé"
plural(5, 'uživatel', 'uživatelé', 'uživatelů')
"uživatelů"
// EN
function plural(n)
{
return arguments[(n === 1) ? 1 : 2];
}
// Examples
plural(1, 'category', 'categories')
"category"
plural(2, 'category', 'categories')
"categories"
plural(5, 'category', 'categories')
"categories"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment