Skip to content

lokalise/node-lokalise-api

Repository files navigation

Lokalise API v2 official Node.js client

npm CI Coverage Status NPM Downloads

Official Node interface for the Lokalise API.

Looking for a simple way to upload/download translations? Try lokalise-file-exchange.

Quickstart

Heads up: starting from v9, this SDK is pure ESM and no longer ships a CommonJS (require) export. Your options:

Install:

npm install @lokalise/node-api

Get a Lokalise API token from your personal profile, then initialize and use the client:

import { LokaliseApi } from "@lokalise/node-api";

const lokaliseApi = new LokaliseApi({ apiKey: "<apiKey>" });

const projects = await lokaliseApi.projects().list();
projects.items[0].name;

const process = await lokaliseApi.files().upload(project_id, {
  data: data_base64,
  filename: "test1.json",
  lang_iso: "en",
});

process.status; // => "queued"

Alternatively, you can use tokens obtained via OAuth2 (note: OAuth tokens expire):

import { LokaliseApiOAuth } from "@lokalise/node-api";

const lokaliseApi = new LokaliseApiOAuth({ apiKey: "<apiKeyObtainedViaOauth2>" });

const projects = await lokaliseApi.projects().list();

Dynamic import example:

(async function () {
  const LokaliseApi = await import("@lokalise/node-api").then((m) => m.LokaliseApi);
  const lokaliseApi = new LokaliseApi({ apiKey: LOKALISE_API_TOKEN });

  // use lokaliseApi here as usual...
})();

Usage

Full docs live at: lokalise.github.io/node-lokalise-api.

Also useful:

License

This library is licensed under the BSD 3 Clause. Prior to version 5.1.0 the license was MIT.

Copyright (c) Lokalise group and Ilya Krukowski