-
-
Save saimonmoore/144435 to your computer and use it in GitHub Desktop.
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
//extend MooTools.lang to add support for pluralization.. | |
(function(){ | |
$extend(MooTools.lang, { | |
pluralise: function(key, delta) { | |
return this.get('Translations', 'pluralise', [key, delta]).substitute({delta: delta}); | |
} | |
}); | |
})(); | |
MooTools.lang.set('en-US', 'Translations', { | |
//each pluralise function is specific to the language | |
// e.g. polish would have a different function as it has multiple plural forms | |
pluralise: function(key, delta) { | |
if (delta <= 1) return MooTools.lang.get('Translations', key)['n' + delta]; | |
return MooTools.lang.get('Translations', key)['n']; | |
}, | |
minutesAgo: {n0: 'zero minutes ago', n1: 'a minute ago', n:'{delta} minutes ago'} | |
}); | |
>>> MooTools.lang.pluralise('minutesAgo', 0); | |
"zero minutes ago" | |
>>> MooTools.lang.pluralise('minutesAgo', 1); | |
"a minute ago" | |
>>> MooTools.lang.pluralise('minutesAgo', 2); | |
"2 minutes ago" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment