diff --git a/chrome/content/zotero/RemoteTranslate.jsm b/chrome/content/zotero/RemoteTranslate.jsm index ba5b75a191..8536ddbb39 100644 --- a/chrome/content/zotero/RemoteTranslate.jsm +++ b/chrome/content/zotero/RemoteTranslate.jsm @@ -67,6 +67,15 @@ class RemoteTranslate { await actor.sendAsyncMessage("initTranslation", { schemaJSON: Zotero.File.getResource('resource://zotero/schema/global/schema.json'), dateFormatsJSON: Zotero.File.getResource('resource://zotero/schema/dateFormats.json'), + // Make only relevant prefs available + // https://github.com/zotero/zotero-connectors/blob/d5f025de9b4f513535cbf4639c6b59bf115d790d/src/common/zotero.js#L264-L265 + prefs: this._getPrefs([ + 'downloadAssociatedFiles', + 'automaticSnapshots', + 'reportTranslationFailure', + 'capitalizeTitles', + 'translators.', + ]), }); } @@ -259,4 +268,20 @@ class RemoteTranslate { } } } + + _getPrefs(keys) { + let rootBranch = 'extensions.zotero.'; // ZOTERO_CONFIG isn't available here + let prefs = {}; + for (let key of keys) { + if (key.endsWith('.')) { + for (let childKey of Zotero.Prefs.rootBranch.getChildList(rootBranch + key)) { + prefs[childKey.substring(rootBranch.length)] = Zotero.Prefs.get(childKey, true); + } + } + else { + prefs[key] = Zotero.Prefs.get(key); + } + } + return prefs; + } } diff --git a/chrome/content/zotero/actors/TranslationChild.jsm b/chrome/content/zotero/actors/TranslationChild.jsm index 256b146428..27a3607dfb 100644 --- a/chrome/content/zotero/actors/TranslationChild.jsm +++ b/chrome/content/zotero/actors/TranslationChild.jsm @@ -49,8 +49,8 @@ class TranslationChild extends JSWindowActorChild { let { name, data } = message; switch (name) { case 'initTranslation': { - let { schemaJSON, dateFormatsJSON } = data; - this._sandbox = this._loadTranslationFramework(schemaJSON, dateFormatsJSON); + let { schemaJSON, dateFormatsJSON, prefs } = data; + this._sandbox = this._loadTranslationFramework(schemaJSON, dateFormatsJSON, prefs); break; } case 'detect': { @@ -257,9 +257,10 @@ class TranslationChild extends JSWindowActorChild { * Load the translation framework into the current page. * @param {Object | String} schemaJSON * @param {Object | String} dateFormatsJSON + * @param {Object} prefs * @return {Sandbox} */ - _loadTranslationFramework(schemaJSON, dateFormatsJSON) { + _loadTranslationFramework(schemaJSON, dateFormatsJSON, prefs) { // Modeled after: // https://searchfox.org/mozilla-esr102/source/toolkit/components/extensions/ExtensionContent.jsm#809-845 let systemPrincipal = Services.scriptSecurityManager.getSystemPrincipal(); @@ -286,6 +287,10 @@ class TranslationChild extends JSWindowActorChild { Zotero.Translators._initialized = true; Zotero.Schema.init(schemaJSON); Zotero.Date.init(dateFormatsJSON); + + for (let [key, value] of Object.entries(prefs)) { + Zotero.Prefs.set(key, value); + } return sandbox; }