Allow calling Zotero.Translate.*.translate without setting translator first.

This simply means that detection code will be run first.
Attempting this with Export translators will fail, because trying to detect a translator does not make sense in this case.
This commit is contained in:
Aurimas Vinckevicius 2014-08-28 18:15:43 -05:00
parent aa005041a8
commit 15722e5022

View file

@ -1112,13 +1112,23 @@ Zotero.Translate.Base.prototype = {
* @param {Boolean} [saveAttachments=true] Exclude attachments (e.g., snapshots) on import
*/
"translate":function(libraryID, saveAttachments) { // initialize properties specific to each translation
this._currentState = "translate";
if(!this.translator || !this.translator.length) {
this.complete(false, new Error("No translator specified"));
var args = arguments;
Zotero.debug("Translate: translate called without specifying a translator. Running detection first.");
this.setHandler('translators', function(me, translators) {
if(!translators.length) {
me.complete(false, "Could not find an appropriate translator");
} else {
me.setTranslator(translators);
Zotero.Translate.Base.prototype.translate.apply(me, args);
}
});
this.getTranslators();
return;
}
this._currentState = "translate";
this._libraryID = libraryID;
this._saveAttachments = saveAttachments === undefined || saveAttachments;
this._savingAttachments = [];
@ -2158,6 +2168,19 @@ Zotero.Translate.Export.prototype._prepareTranslation = function() {
this._sandboxManager.importObject(this._io);
}
/**
* Overload Zotero.Translate.Base#translate to make sure that
* Zotero.Translate.Export#translate is not called without setting a
* translator first. Doesn't make sense to run detection for export.
*/
Zotero.Translate.Export.prototype.translate = function() {
if(!this.translator || !this.translator.length) {
this.complete(false, new Error("Export translation initiated without setting a translator"));
} else {
Zotero.Translate.Base.prototype.translate.apply(this, arguments);
}
};
/**
* Return the progress of the import operation, or null if progress cannot be determined
*/