What is @lokalise/node-api?
@lokalise/node-api is an official Node.js client for the Lokalise API, which allows developers to interact with the Lokalise platform programmatically. Lokalise is a translation management system that helps teams manage localization projects. This package provides a way to automate tasks such as managing projects, uploading and downloading files, and handling translations.
What are @lokalise/node-api's main functionalities?
Managing Projects
This feature allows you to create and manage projects on Lokalise. The code sample demonstrates how to create a new project with a specified name, description, and languages.
const LokaliseApi = require('@lokalise/node-api');
const lokaliseApi = new LokaliseApi({ apiKey: 'your_api_key' });
async function createProject() {
const project = await lokaliseApi.projects.create({
name: 'New Project',
description: 'A new project description',
languages: [{ lang_iso: 'en' }]
});
console.log(project);
}
createProject();
Uploading Files
This feature allows you to upload translation files to a specific project. The code sample demonstrates how to upload a file by providing the project ID, base64 encoded file content, filename, and language ISO code.
const LokaliseApi = require('@lokalise/node-api');
const lokaliseApi = new LokaliseApi({ apiKey: 'your_api_key' });
async function uploadFile() {
const upload = await lokaliseApi.files.upload('project_id', {
data: 'base64_encoded_file_content',
filename: 'translations.json',
lang_iso: 'en'
});
console.log(upload);
}
uploadFile();
Downloading Files
This feature allows you to download translation files from a specific project. The code sample demonstrates how to download files by providing the project ID and specifying the format and whether to use original filenames.
const LokaliseApi = require('@lokalise/node-api');
const lokaliseApi = new LokaliseApi({ apiKey: 'your_api_key' });
async function downloadFile() {
const download = await lokaliseApi.files.download('project_id', {
format: 'json',
original_filenames: true
});
console.log(download);
}
downloadFile();
Handling Translations
This feature allows you to handle translations within a project. The code sample demonstrates how to add a new translation key with its corresponding translations by providing the project ID, key name, and translations.
const LokaliseApi = require('@lokalise/node-api');
const lokaliseApi = new LokaliseApi({ apiKey: 'your_api_key' });
async function addTranslation() {
const translation = await lokaliseApi.keys.create('project_id', {
keys: [{
key_name: 'welcome_message',
translations: [{
language_iso: 'en',
translation: 'Welcome!'
}]
}]
});
console.log(translation);
}
addTranslation();
Other packages similar to @lokalise/node-api
i18next
i18next is a popular internationalization framework for JavaScript. It provides a complete solution for localizing applications, including support for translation files, language detection, and interpolation. Compared to @lokalise/node-api, i18next focuses more on the client-side implementation of localization rather than managing translation projects.
gettext-parser
gettext-parser is a library for parsing and compiling gettext files (PO and MO files). It is useful for applications that use gettext for localization. While @lokalise/node-api provides a comprehensive API for managing translation projects on Lokalise, gettext-parser is more focused on handling gettext file formats.
node-polyglot
node-polyglot is a lightweight internationalization library for Node.js. It provides a simple way to manage translations and supports interpolation and pluralization. Compared to @lokalise/node-api, node-polyglot is more suitable for small-scale localization needs and does not offer project management features.
Lokalise API v2 official Node.js client
Official Node interface for the Lokalise API.
Quickstart
Install the library:
npm install @lokalise/node-api
Obtain Lokalise API token in your personal profile, initialize and use the client:
const { LokaliseApi } = require('@lokalise/node-api');
const lokaliseApi = new LokaliseApi({ apiKey: '<apiKey>'});
const projects = lokaliseApi.projects.list();
projects[0].name;
process = await lokaliseApi.files.upload(project_id,
{data: data_base64, filename: 'test1.json', lang_iso: 'en'})
process.status
Usage
Detailed documentation can be found at lokalise.github.io/node-lokalise-api.
License
This library is licensed under the BSD 3 Clause. Prior to version 5.1.0 the license was MIT.
Copyright (c) Lokalise group, Ilya Bodrov