How Zotero gets reference data from sites
Clicking [the Zotero] icon saves reference information to the Zotero library. Such functionality is made possible by ’translators’ – short pieces of computer code, or scripts[9] to understand the structure of web pages and to parse them into citations using its internal formats
Zotero’s translators are each a JavaScript file in github.com/zotero/translators. There are over 700 translators. Each one is for a different site. For example, here is the translator for Wikipedia.
dev:translators [Zotero Documentation]
Zotero often refers to their browser extension as “the Connector”.
The Connector runs a background process (Chrome/Firefox/Safari) which works as a middle-layer between the translation framework running in inject scripts (a) and Zotero (c) or zotero.org (d).
The background process maintains a cache of translators and performs the initial translator detection using URL matching. Translators whose target regexp matches the URL of a given webpage are then further tested by running
detectWeb()
in injected scripts. A list of translators and their code is fetched either from Zotero (c) or zotero.org (d).The background process is also responsible for updating the extension UI, kicking off translations, storing and retrieving connector preferences and sending translated items to Zotero or zotero.org. Browser specific scripts are available for BrowserExt and Safari.
// Enumeration of types of translators
var TRANSLATOR_TYPES = {"import":1, "export":2, "web":4, "search":8};
// Properties required for every translator
var TRANSLATOR_REQUIRED_PROPERTIES = ["translatorID", "translatorType", "label", "creator", "target", "priority", "lastUpdated"];
// Properties that are preserved if present
var TRANSLATOR_OPTIONAL_PROPERTIES = ["targetAll", "browserSupport", "minVersion", "maxVersion", "inRepository", "configOptions", "displayOptions", "hiddenPrefs", "itemType"];
// Properties that are passed from background to inject page in connector
var TRANSLATOR_PASSING_PROPERTIES = TRANSLATOR_REQUIRED_PROPERTIES
.concat(["targetAll", "browserSupport", "code", "runMode", "itemType", "inRepository"]);
var TRANSLATOR_CACHING_PROPERTIES = TRANSLATOR_REQUIRED_PROPERTIES
.concat(["browserSupport", "targetAll"]);
The main repo for Zotero’s browser extension is zotero-connectors, but this repo has submodules including translate, utilities, zotero, and zotero-google-docs-integration.
Some of the extension’s most important files are manifest.json and background.js.
types
- aurimasv.github.io/z2csl/typeMap.xml
- CSL properties in utilities/utilities_item.js
- CLS properties in zotero-schema/schema.json
- item types, fields, and creator types in zotero-schema/schema.json