Translators are at the core of one of Zotero’s most popular features: its ability to import and export item metadata from and to a variety of formats. Below we describe how translators work, and how you can write your own.
This page describes the function and structure of translators. For in-depth documentation on how to write translator code, see Coding.
Note: Before writing a translator for a site, look at the documentation on exposing metadata; website authors should try embedding the necessary metadata before attempting to write a translator.
If you're looking for a broken translator to fix, see the recent translator errors and check on one of the top reported errors. You can also check the status of many translators by reviewing the translator test overview.
Zotero translators can operate in four different ways (note that translators are not necessarily restricted to a single type):
Zotero translators are stored as individual JavaScript files in the “translators” subdirectory of the Zotero data directory. Each translator contains a JSON metadata header, followed by the translator’s JavaScript code. This code must include certain top-level JavaScript functions, as determined by the translator type(s).
An example of a JSON metadata header is shown below:
{ "translatorID": "fcf41bed-0cbc-3704-85c7-8062a0068a7a", "label": "NCBI PubMed", "creator": "Simon Kornblith, Michael Berkowitz, Avram Lyon, and Rintze Zelle", "target": "https?://[^/]*(www|preview)[\\.\\-]ncbi[\\.\\-]nlm[\\.\\-]nih[\\.\\-]gov[^/]*/(?:m/)?(books|pubmed|sites/pubmed|sites/entrez|entrez/query\\.fcgi\\?.*db=PubMed|myncbi/browse/collection/|myncbi/collections/)", "minVersion": "2.1.9", "maxVersion": "", "priority": 100, "inRepository": true, "translatorType": 13, "browserSupport": "gcsbv", "lastUpdated": "2014-06-20 04:23:04" }
The roles of the different metadata fields are:
translatorID
is used for automatic updating of translators, and for calling translators within other translators.translatorType
is 2 for an export translator, and 13 for a search/web/import translator, because 13=8+4+1.target
should specify a JavaScript regular expression (note that escaping requires two backslashes: one for the regular expression itself, and one for the JSON, e.g. “^https?://(www\\.)?example.com/”. If using Scaffold, it takes care of the JSON escaping, so backslashes do not need to be escaped).detectWeb
function is run. If this function finds item metadata, the Zotero translator icon appears or becomes active in the browser. When multiple translators have a matching target, the translator with the lowest priority number is selected. Web translators with an empty target
string (e.g. the DOI translator) match every webpage, but normally have a high priority number and are only used when no other translator matches.target
is set to the expected extension (e.g. the BibTeX import/export translator has its target set to “bib”; selecting BibTex in Zotero’s import window filters for files with a “.bib” extension).target
is set to the extension that should be given to generated files (e.g. the BibTeX translator produces “filename.bib” files).g
, c
, s
, i
, representing the connectors that the translator can be run in – Gecko (Firefox), Chrome, Safari, Internet Explorer, respectively. b
indicates support for the Bookmarklet (zotero-dev thread) and v
indicates support for the translation-server. For more information, see Connectors.true
for translators that are added to the Zotero repo and distributed to all Zotero users, and false
for those that are not.In addition to the required metadata fields described above, two optional fields exist, configOptions and displayOptions. Both are JavaScript objects, with several properties that control translator behavior:
Zotero.RDF
object. If “xml/dom”, Zotero will expose the data through the function Zotero.getXML()
. Zotero does not natively support importing N3 representations of RDF. The values “block” and “line” are deprecated and no longer necessary in Zotero 2.1 and later.true
or false
. If true
, an export translator will have access to the collection names and can recreate them in the exported file.true
, and unchecked if the property is set to false
.An example of how these properties are set (taken from the BibTeX.js translator):
"configOptions": {"getCollections": true}, "displayOptions": {"exportCharset": "UTF-8", "exportNotes": true, "exportFileData": false, "useJournalAbbreviation": false}
Depending on the translator type, each Zotero translator must include certain top-level JavaScript functions:
detectWeb
is run to determine whether item metadata can indeed be retrieved from the webpage. Should return the detected item type (e.g. “journalArticle”, see the overview of Zotero item types), or, if multiple items are found, “multiple”. If detectWeb
does not return a value, the translator with the next-highest priority is selected, until all translators with a matching target have been exhausted.true
if it can, and false
if it cannot.true
if it can, and false
if it cannot.See Translator Coding for a detailed description on how these functions can be coded.
The following tools can make coding Zotero translators easier:
If you created or modified a translator and wish to have it added to Zotero, or are looking for support on writing translators, please submit a pull request to the Zotero Translators GitHub repo. You can also ask questions about translator development on Zotero development mailing list.
To submit a pull request, fork the Zotero Translator GitHub repository, commit your changes (i.e., adding or modifying translator files), and create a pull request. You can use your Git client of choice, but for new users we recommend SmartGit, which is free for non-commercial purposes.
When you submit a pull request on GitHub, your translator code will be reviewed, and you will receive comments from the Zotero developers or experienced volunteers. Once you've made any necessary changes, your translator will be added to the Zotero translator repository.
Please note that contributed translators need to be licensed in a way that allows the Zotero project to distribute them and modify them. We encourage you to license new translators under the GNU Affero General Public License version 3 (or later), which is the license used for Zotero. To do so, just add a license statement to the top of the file. Take a look a recently committed translator, like “Die Zeit.js”, for an example of such a statement.
While there are no strict coding guidelines for translators, there are some general recommendations:
detectWeb
functions that are run for each page.detectWeb
, detectImport
and detectSearch
should be coded to minimize the likelihood of the corresponding doWeb
, etc. function failing. Do your minimum required input checking the detect functions – a failing do
function will cause user-visible errors.zotero/translators
repository: npm ci && npm run lint -- "Your Translator.js"