diff --git a/chrome/content/zotero/recognizePDF.js b/chrome/content/zotero/recognizePDF.js index 72b6cb3ca7..ae3df74941 100644 --- a/chrome/content/zotero/recognizePDF.js +++ b/chrome/content/zotero/recognizePDF.js @@ -363,7 +363,7 @@ Zotero_RecognizePDF.Recognizer.prototype._queryGoogle = function() { var me = this; if(this._DOI) { // use CrossRef to look for DOI - var translate = new Zotero.Translate("search"); + var translate = new Zotero.Translate.Search(); translate.setTranslator("11645bd1-0420-45c1-badb-53fb41eeb753"); var item = {"itemType":"journalArticle", "DOI":this._DOI}; translate.setSearch(item); @@ -411,7 +411,7 @@ Zotero_RecognizePDF.Recognizer.prototype._queryGoogle = function() { this._hiddenBrowser.docShell.allowImages = false; } - var translate = new Zotero.Translate("web"); + var translate = new Zotero.Translate.Web(); var savedItem = false; translate.setTranslator("57a00950-f0d1-4b41-b6ba-44ff0fc30289"); translate.setHandler("itemDone", function(translate, item) { @@ -425,6 +425,13 @@ Zotero_RecognizePDF.Recognizer.prototype._queryGoogle = function() { translate.setHandler("done", function(translate, success) { if(!success || !savedItem) me._queryGoogle(); }); + translate.setHandler("translators", function(translate, detected) { + if(detected.length) { + translate.translate(me._libraryID, false); + } else { + me._queryGoogle(); + } + }); this._hiddenBrowser.addEventListener("pageshow", function() { me._scrape(translate) }, true); @@ -459,10 +466,11 @@ Zotero_RecognizePDF.Recognizer.prototype._scrape = function(/**Zotero.Translate* this._callback(false, "recognizePDF.limit"); return; } - + this._hiddenBrowser.removeEventListener("pageshow", this._scrape.caller, true); translate.setDocument(this._hiddenBrowser.contentDocument); - translate.translate(this._libraryID, false); + + translate.getTranslators(false, true); } /** diff --git a/chrome/content/zotero/xpcom/translation/translate.js b/chrome/content/zotero/xpcom/translation/translate.js index 86403f6b63..85ff370346 100644 --- a/chrome/content/zotero/xpcom/translation/translate.js +++ b/chrome/content/zotero/xpcom/translation/translate.js @@ -892,15 +892,41 @@ Zotero.Translate.Base.prototype = { * * @param {Boolean} [getAllTranslators] Whether all applicable translators should be returned, * rather than just the first available. + * @param {Boolean} [checkSetTranslator] If true, the appropriate detect function is run on the + * set document/text/etc. using the translator set by setTranslator. + * getAllTranslators parameter is meaningless in this context. * @return {Zotero.Translator[]} An array of {@link Zotero.Translator} objects */ - "getTranslators":function(getAllTranslators) { + "getTranslators":function(getAllTranslators, checkSetTranslator) { // do not allow simultaneous instances of getTranslators if(this._currentState === "detect") throw new Error("getTranslators: detection is already running"); this._currentState = "detect"; this._getAllTranslators = getAllTranslators; - this._getTranslatorsGetPotentialTranslators(); - + + if(checkSetTranslator) { + // setTranslator must be called beforehand if checkSetTranslator is set + if( !this.translator || !this.translator[0] ) { + throw new Error("getTranslators: translator must be set via setTranslator before calling" + + " getTranslators with the checkSetTranslator flag"); + } + var translators = new Array(); + var t; + for(var i=0, n=this.translator.length; i