Code Monkey home page Code Monkey logo

bib's Introduction

Zotero Translation Client

Overview

Zotero Translation Client is a library that can process URLs and identifiers (such as ISBN or DOI) into CSL-JSON bibliography items using translation server, optionally persisting these items in a storage object provided.

Compatibility

Current version of Translation Client (2.x.x) is compatible with Translation Server v2. For compatiblity with v1, please use 1.x.x version.

Getting The Library

npm i zotero-translation-client

Quick start

  1. Install and start translation server

  2. Configure the library to work with the translation server

const ZoteroTranslationClient = require('zotero-translation-client');
let translationClient = new ZoteroTranslationClient({
	persist: false,
	translateURL: 'http://my-translation.server.example.com:1234'
});
  1. Translate some urls
const { items: [ myPaper ] } = await translationClient.translateUrl('http://example.com/paper');
console.log(myPaper);

In-memory Storage

Normally each call to translateUrl returns an item and also caches it in memory. Cached items can be retrieved at any time, either as Zotero Items:

const [ myPaper ] = translationClient.itemsRaw;

Or in CSL-JSON format:

const [ myPaperAsCSL ] = translationClient.itemsCSL;

This behaviour can be prevented using second, optional argument to translationClient.translate, i.e. calling translationClient.translateUrl(url, { add: false }) will return a translated item but won't store it anywhere.

Persistence

In the example above, after refreshing the page (or restarting a node script), all previosly translated, cached items are lost. If that's not desired behaviour, Zotero Translation Client accepts any Web Storage compatible container for persistance. In fact, by default, it will attempt to use Local Storage for persistence.

If you're running Zotero Translation Client in node, you'll either need to disable persistence (as in the example above) or provide your own Web Storage compatible container (e.g. node-localstorage):

const LocalStorage = require('node-localstorage').LocalStorage;
const fileStorage = new LocalStorage('./my-citations');

let translationClient = new ZoteroTranslationClient({
	storage: fileStorage,
	translateURL: 'http://my-translation.server.example.com:1234'
});

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.