From 8660095c549da3298e8f3bcd8adbc18e61deae8e Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Sat, 25 Oct 2008 20:55:02 +0000 Subject: [PATCH] Fixes #1182, Translator priority is ignored --- chrome/content/zotero/xpcom/translate.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/chrome/content/zotero/xpcom/translate.js b/chrome/content/zotero/xpcom/translate.js index f2034ed22f..4924879ae8 100644 --- a/chrome/content/zotero/xpcom/translate.js +++ b/chrome/content/zotero/xpcom/translate.js @@ -78,6 +78,21 @@ Zotero.Translators = new function() { i++; } + // Sort by priority + var collation = Zotero.getLocaleCollation(); + var cmp = function (a, b) { + if (a.priority > b.priority) { + return 1; + } + else if (a.priority < b.priority) { + return -1; + } + return collation.compareString(1, a.label, b.label); + } + for (var type in _cache) { + _cache[type].sort(cmp); + } + Zotero.debug("Cached "+i+" translators in "+((new Date()).getTime() - start)+" ms"); } @@ -115,6 +130,7 @@ Zotero.Translators = new function() { * @property {Integer} translatorType Type of the translator (use bitwise & with TRANSLATOR_TYPES to read) * @property {String} label Human-readable name of the translator * @property {String} target Location that the translator processes + * @property {Integer} priority Lower-priority translators will be selected first * @property {Boolean} inRepository Whether the translator may be found in the repository * @property {String} lastUpdated SQL-style date and time of translator's last update * @property {String} code The executable JavaScript for the translator @@ -148,7 +164,7 @@ Zotero.Translator = function(file) { if(info) { var haveMetadata = true; // make sure we have all the properties - for each(var property in ["translatorID", "translatorType", "label", "target", "lastUpdated"]) { + for each(var property in ["translatorID", "translatorType", "label", "target", "priority", "lastUpdated"]) { if(info[property] === undefined) { this.logError('Missing property "'+property+'" in translator metadata JSON object'); haveMetadata = false;