From f2af77498ba3e312d92c3765365a4f1dff1f7901 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Fri, 7 Jul 2017 18:18:00 -0400 Subject: [PATCH] Allow single string in Zotero.Utilities.pluralize() Zotero.Utilities.pluralize(5, 'tag') will produce 'tags' automatically --- chrome/content/zotero/xpcom/utilities.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/chrome/content/zotero/xpcom/utilities.js b/chrome/content/zotero/xpcom/utilities.js index 269227db8..872a3f598 100644 --- a/chrome/content/zotero/xpcom/utilities.js +++ b/chrome/content/zotero/xpcom/utilities.js @@ -873,11 +873,15 @@ Zotero.Utilities = { * 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 + * @param {String[]|String} forms - If an array, an array of plural forms (e.g., ['object', 'objects']); + * currently only the two English forms are supported, for 1 and 0/many. If a single string, + * 's' is added automatically for 0/many. * @return {String} */ pluralize: function (num, forms) { + if (typeof forms == 'string') { + forms = [forms, forms + 's']; + } return num == 1 ? forms[0] : forms[1]; },