Add Zotero.Utilities.pluralize()

This makes it a little easier to use the proper plural form of a word.
Currently this only supports English forms and is used only in debug
output. For proper plural form support, use PluralForm.jsm.
This commit is contained in:
Dan Stillman 2017-05-05 00:19:09 -04:00
parent 397ea5875a
commit b30e168c21

View file

@ -866,6 +866,22 @@ Zotero.Utilities = {
return str + '\u2026' + (countChars ? ' (' + str.length + ' chars)' : '');
},
/**
* Return the proper plural form of a string
*
* For now, this is only used for debug output in English.
*
* @param {Integer} num
* @param {String[]} forms - An array of plural forms (e.g., ['object', 'objects']); currently only
* the two English forms are supported, for 1 and 0/many
* @return {String}
*/
pluralize: function (num, forms) {
return num == 1 ? forms[0] : forms[1];
},
/**
* Port of PHP's number_format()
*