commit 15722e5022b8aa2e9aebc174e0e98a2de4c49f15
parent aa005041a8d06933ab772f1b87b7c84b72a05912
Author: Aurimas Vinckevicius <aurimas.dev@gmail.com>
Date: Thu, 28 Aug 2014 18:15:43 -0500
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.
Diffstat:
1 file changed, 26 insertions(+), 3 deletions(-)
diff --git a/chrome/content/zotero/xpcom/translation/translate.js b/chrome/content/zotero/xpcom/translation/translate.js
@@ -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 = [];
@@ -2159,6 +2169,19 @@ Zotero.Translate.Export.prototype._prepareTranslation = function() {
}
/**
+ * 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
*/
Zotero.Translate.Export.prototype.getProgress = function() {