
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
@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.
Install the library:
npm install @lokalise/node-api@~8.0.2
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 = 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):
const { LokaliseApiOAuth } = require('@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 76,543 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 16 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
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.