commit b30e168c2146ce4d5243b377303aa9ff26d469be
parent 397ea5875abd44894ef33abc24b5320f83a98a58
Author: Dan Stillman <dstillman@zotero.org>
Date: Fri, 5 May 2017 00:19:09 -0400
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.
Diffstat:
1 file changed, 16 insertions(+), 0 deletions(-)
diff --git 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()
*