Skip to content

Repository files navigation

Lokalise Node.js SDK

npm CI Code Coverage Maintainability NPM Downloads

Official Node.js SDK for the Lokalise Expert and Vantage APIs.

  • Expert API: Manage projects, translations, files, tasks, and other resources. See the Expert API reference.
  • Vantage API: Manage projects, content, uploads, imports, exports, and translation workflows. See the Vantage API reference.

Looking for a simple way to upload and download translations in Lokalise Expert? Try lokalise-file-exchange.

Quickstart

Install the package:

npm install @lokalise/node-api

Get a Lokalise API token from your personal profile, then initialize the client for the API you want to use.

Expert API

Use LokaliseApi to work with Expert projects, translations, files, and other resources.

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

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

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

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

process.status; // "queued"

Vantage API

Use LokaliseApiVantage to work with Vantage projects, content, uploads, imports, and exports.

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

const lokaliseVantageApi = new LokaliseApiVantage({
	apiKey: "<apiKey>",
});

// List projects in a team.
const projects = await lokaliseVantageApi.projects().list({
	team_id: "<teamId>",
	limit: 10,
});

projects.items[0].name;

// List project items.
const items = await lokaliseVantageApi.projectItems().list({
	project_id: "<projectId>",
	limit: 10,
});

items.items[0].name;

Both clients use the same API token. You can initialize both in the same application if you need to work with Expert and Vantage projects.

OAuth2 authentication

For the Expert API, you can alternatively 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 imports

You can also import the API clients dynamically:

const { LokaliseApi, LokaliseApiVantage } = await import("@lokalise/node-api");

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

const vantageApi = new LokaliseApiVantage({
	apiKey: "<apiKey>",
});

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

Releases

Used by

Contributors

Languages