Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
@lokalise/node-api
Advanced tools
@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.
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();
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 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 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.
Official Node interface for the Lokalise API.
Please note that starting from version 9 this SDK is a pure ESM module. It does not provide a CommonJS export (require
) anymore. Therefore you should either convert your project to ESM, use dynamic import, or stay on version 8 which we are fully supporting.
Install the library:
npm install @lokalise/node-api
Obtain Lokalise API token in your personal profile, 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;
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 (don't forget that these tokens have expiration dates):
import { LokaliseApiOAuth } from "@lokalise/node-api";
const lokaliseApi = new LokaliseApiOAuth({ apiKey: '<apiKeyObtainedViaOauth2>' });
const projects = lokaliseApi.projects().list();
Detailed documentation can be found at lokalise.github.io/node-lokalise-api.
You can also check this repo containing some usage examples and this blog post with explanations.
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
FAQs
Official Lokalise API 2.0 Node.js client
The npm package @lokalise/node-api receives a total of 131,640 weekly downloads. As such, @lokalise/node-api popularity was classified as popular.
We found that @lokalise/node-api demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 13 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.