From b30e168c2146ce4d5243b377303aa9ff26d469be Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Fri, 5 May 2017 00:19:09 -0400 Subject: [PATCH] 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. --- chrome/content/zotero/xpcom/utilities.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/chrome/content/zotero/xpcom/utilities.js b/chrome/content/zotero/xpcom/utilities.js index 4724119c4a..d3a76ef51c 100644 --- a/chrome/content/zotero/xpcom/utilities.js +++ b/chrome/content/zotero/xpcom/utilities.js @@ -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() *