From 810e0a32395db415c9554740989819754e1d392f Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Thu, 16 Nov 2017 01:18:42 -0500 Subject: [PATCH] Add Zotero.getStringFromBundle() The same as Zotero.getString(), but takes an nsIStringBundle as the first parameter. Extensions could use this to get the same getString() features with their own properties files. --- chrome/content/zotero/xpcom/zotero.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/chrome/content/zotero/xpcom/zotero.js b/chrome/content/zotero/xpcom/zotero.js index 847c41e357..72e74fef61 100644 --- a/chrome/content/zotero/xpcom/zotero.js +++ b/chrome/content/zotero/xpcom/zotero.js @@ -1407,15 +1407,20 @@ Services.scriptloader.loadSubScript("resource://zotero/polyfill.js"); * separated by semicolons */ this.getString = function (name, params, num) { + return this.getStringFromBundle(_localizedStringBundle, ...arguments); + } + + + this.getStringFromBundle = function (bundle, name, params, num) { try { if (params != undefined) { if (typeof params != 'object'){ params = [params]; } - var l10n = _localizedStringBundle.formatStringFromName(name, params, params.length); + var l10n = bundle.formatStringFromName(name, params, params.length); } else { - var l10n = _localizedStringBundle.GetStringFromName(name); + var l10n = bundle.GetStringFromName(name); } if (num !== undefined) { let availableForms = l10n.split(/;/); @@ -1435,10 +1440,9 @@ Services.scriptloader.loadSubScript("resource://zotero/polyfill.js"); Zotero.debug(params, 1); } else if (e.name != 'NS_ERROR_FAILURE') { - Components.utils.reportError(e); - Zotero.debug(e, 1); + Zotero.logError(e); } - throw ('Localized string not available for ' + name); + throw new Error('Localized string not available for ' + name); } return l10n; }