node-lokalise-api
v1.0.0
Published
Lokalise API
Downloads
113
Maintainers
Readme
node-lokalise-api
Simple NodeJS wrapper around Lokalise service.
Localise API documentation can be found here
Detail package documentation can be found here
- Install
- Usage
- API
- Development
- License
- Support
Install
Install package as yet another npm library with command:
npm install node-lokalise-api
Also you can use another package manager, for example yarn:
yarn add node-lokalise-api
Usage
Include in your module:
const {LokaliseAPI} = require('node-lokalise-api');
const api = new LokaliseAPI({
token: '<your-lokalise-api-token>'
});
// get comments for your project
const result = await api.comments.list('<project id>', null, {page: 1, limit: 100});
Avaiable options are:
token
- access token for Lokalizetimeout
- maximum allowed time for request in millieconds. (10000 by default)retry
- number of allowed retry attempts for failed requests. (2 by default)baseUrl
- base url for Lokalize API endpoints. By default it is https://api.lokalise.co/api2.
API
Comments
List project comments
const {LokaliseAPI} = require('node-lokalise-api');
const api = new LokaliseAPI({token: '<your-lokalise-api-token>'});
const result = await api.comments.list('<project id>', null, {page: 1, limit: 100});
List key comments
const {LokaliseAPI} = require('node-lokalise-api');
const api = new LokaliseAPI({token: '<your-lokalise-api-token>'});
const result = await api.comments.list('<project id>', '<key id>', {page: 1, limit: 100});
Create comments
const {LokaliseAPI} = require('node-lokalise-api');
const api = new LokaliseAPI({token: '<your-lokalise-api-token>'});
const result = await api.comments.create('<project id>', '<key id>', {
comments: [
{comment: 'This is a test.'},
{comment: 'Adding multiple comments.'}
]
});
Retrieve a comment
const {LokaliseAPI} = require('node-lokalise-api');
const api = new LokaliseAPI({token: '<your-lokalise-api-token>'});
const result = await api.comments.get('<project id>', '<key id>', '<comment id>');
Delete a comment
const {LokaliseAPI} = require('node-lokalise-api');
const api = new LokaliseAPI({token: '<your-lokalise-api-token>'});
const result = await api.comments.delete('<project id>', '<key id>', '<comment id>');
Contributors
List all contributors
const {LokaliseAPI} = require('node-lokalise-api');
const api = new LokaliseAPI({token: '<your-lokalise-api-token>'});
const result = await api.contributors.list('<project id>', {page: 1, limit: 100});
Create contributors
const {LokaliseAPI} = require('node-lokalise-api');
const api = new LokaliseAPI({token: '<your-lokalise-api-token>'});
const result = await api.contributors.create('<project id>', {
contributors: [
{
email: '[email protected]',
fullname: 'Mr. Translator',
is_admin: false,
is_reviewer: true,
languages: [
{
lang_iso: en,
is_writable: false
},
{
lang_iso: ru,
is_writable: true
}
],
admin_rights: [
'keys', 'languages'
]
}
]
});
Retrieve a contributor
const {LokaliseAPI} = require('node-lokalise-api');
const api = new LokaliseAPI({token: '<your-lokalise-api-token>'});
const result = await api.contributors.get('<project id>', '<contributor id>');
Update a contributor
const {LokaliseAPI} = require('node-lokalise-api');
const api = new LokaliseAPI({token: '<your-lokalise-api-token>'});
const result = await api.contributors.update('<project id>', '<contributor id>', {
is_admin: true
});
Delete a contributor
const {LokaliseAPI} = require('node-lokalise-api');
const api = new LokaliseAPI({token: '<your-lokalise-api-token>'});
const result = await api.contributors.delete('<project id>', '<contributor id>');
Files
List all files
const {LokaliseAPI} = require('node-lokalise-api');
const api = new LokaliseAPI({token: '<your-lokalise-api-token>'});
const result = await api.files.list('<project id>', {page: 1, limit: 100});
Upload a file
const {LokaliseAPI} = require('node-lokalise-api');
const api = new LokaliseAPI({token: '<your-lokalise-api-token>'});
const result = await api.files.upload('<project id>', {
filename: 'index.json',
data: 'D94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGL.....',
lang_iso: 'en',
tags: [
'index', 'admin', 'v2.0'
],
convert_placeholders: true
});
Download files
const {LokaliseAPI} = require('node-lokalise-api');
const api = new LokaliseAPI({token: '<your-lokalise-api-token>'});
const result = await api.files.download('<project id>', {
format: 'json',
original_filenames: true
});
Keys
List all keys
const {LokaliseAPI} = require('node-lokalise-api');
const api = new LokaliseAPI({token: '<your-lokalise-api-token>'});
const result = await api.keys.list('<project id>', {page: 1, limit: 100});
Create keys
const {LokaliseAPI} = require('node-lokalise-api');
const api = new LokaliseAPI({token: '<your-lokalise-api-token>'});
const result = await api.keys.create('<project id>', {
keys: [
{
key_name: 'index.welcome',
description: 'Index app welcome',
platforms: ['web'],
translations: [
{
language_iso: 'en',
translation: 'Welcome'
}
]
}
]
});
Retrieve a key
const {LokaliseAPI} = require('node-lokalise-api');
const api = new LokaliseAPI({token: '<your-lokalise-api-token>'});
const result = await api.keys.get('<project id>', '<key id>');
Update a key
const {LokaliseAPI} = require('node-lokalise-api');
const api = new LokaliseAPI({token: '<your-lokalise-api-token>'});
const result = await api.keys.update('<project id>', '<key id>', {
platforms: ['web', 'other'],
description: 'Index app welcome'
});
Bulk update
const {LokaliseAPI} = require('node-lokalise-api');
const api = new LokaliseAPI({token: '<your-lokalise-api-token>'});
const result = await api.keys.updateMany('<project id>', {
keys: [
{
key_id: 331223,
key_name: 'index.welcome',
description: 'Index app welcome',
platforms: ['web']
},
{
key_id: 331224,
key_name: 'index.hello',
description: 'Index greetings',
platforms: ['web']
}
]
});
Delete multiple keys
const {LokaliseAPI} = require('node-lokalise-api');
const api = new LokaliseAPI({token: '<your-lokalise-api-token>'});
const result = await api.keys.deleteMany('<project id>', {
keys: [12345, 12346]
});
Delete a key
const {LokaliseAPI} = require('node-lokalise-api');
const api = new LokaliseAPI({token: '<your-lokalise-api-token>'});
const result = await api.keys.delete('<project id>', '<key id>');
Languages
List system languages
const {LokaliseAPI} = require('node-lokalise-api');
const api = new LokaliseAPI({token: '<your-lokalise-api-token>'});
const result = await api.languages.list(null, {page: 1, limit: 100});
List project languages
const {LokaliseAPI} = require('node-lokalise-api');
const api = new LokaliseAPI({token: '<your-lokalise-api-token>'});
const result = await api.languages.list('<project id>', {page: 1, limit: 100});
Create languages
const {LokaliseAPI} = require('node-lokalise-api');
const api = new LokaliseAPI({token: '<your-lokalise-api-token>'});
const result = await api.languages.create('<project id>', {
languages: [
{lang_iso: 'en'},
{lang_iso: 'ru'}
]
});
Retrieve a language
const {LokaliseAPI} = require('node-lokalise-api');
const api = new LokaliseAPI({token: '<your-lokalise-api-token>'});
const result = await api.languages.get('<project id>', '<language id>');
Update a language
const {LokaliseAPI} = require('node-lokalise-api');
const api = new LokaliseAPI({token: '<your-lokalise-api-token>'});
const result = await api.languages.update('<project id>', '<language id>', {
lang_iso: 'en-US',
plural_forms: [
'one', 'zero', 'few', 'other'
]
});
Delete a language
const {LokaliseAPI} = require('node-lokalise-api');
const api = new LokaliseAPI({token: '<your-lokalise-api-token>'});
const result = await api.languages.delete('<project id>', '<language id>');
Projects
List all projects
const {LokaliseAPI} = require('node-lokalise-api');
const api = new LokaliseAPI({token: '<your-lokalise-api-token>'});
const result = await api.projects.list({page: 1, limit: 100});
Create a project
const {LokaliseAPI} = require('node-lokalise-api');
const api = new LokaliseAPI({token: '<your-lokalise-api-token>'});
const result = await api.projects.create({
name: 'TheApp Project',
description: 'iOS + Android strings of TheApp. https://theapp.com'
});
Retrieve a project
const {LokaliseAPI} = require('node-lokalise-api');
const api = new LokaliseAPI({token: '<your-lokalise-api-token>'});
const result = await api.projects.get('<project id>');
Update a project
const {LokaliseAPI} = require('node-lokalise-api');
const api = new LokaliseAPI({token: '<your-lokalise-api-token>'});
const result = await api.projects.update('<project id>', {
name: 'TheZapp Project',
description: 'iOS + Android strings of TheZapp. https://thezapp.com'
});
Empty a project
const {LokaliseAPI} = require('node-lokalise-api');
const api = new LokaliseAPI({token: '<your-lokalise-api-token>'});
const result = await api.projects.empty('<project id>');
Delete a project
const {LokaliseAPI} = require('node-lokalise-api');
const api = new LokaliseAPI({token: '<your-lokalise-api-token>'});
const result = await api.projects.delete('<project id>');
Screenshots
List all screenshots
const {LokaliseAPI} = require('node-lokalise-api');
const api = new LokaliseAPI({token: '<your-lokalise-api-token>'});
const result = await api.screenshots.list('<project id>', {page: 1, limit: 100});
Create screenshots
const {LokaliseAPI} = require('node-lokalise-api');
const api = new LokaliseAPI({token: '<your-lokalise-api-token>'});
const result = await api.screenshots.create('<project id>', {
screenshots: [
{
data: 'data:image/jpeg;base64,D94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGL',
ocr: false,
key_ids: [
1132290, 1132292, 1132293
],
tags: [
'onboarding'
]
}
]
});
Retrieve a screenshot
const {LokaliseAPI} = require('node-lokalise-api');
const api = new LokaliseAPI({token: '<your-lokalise-api-token>'});
const result = await api.screenshots.get('<project id>', '<screenshot id>');
Update a screenshot
const {LokaliseAPI} = require('node-lokalise-api');
const api = new LokaliseAPI({token: '<your-lokalise-api-token>'});
const result = await api.screenshots.update('<project id>', '<screenshot id>', {
key_ids: [
1132290, 1132292
],
tags: [
'main'
]
});
Delete a screenshot
const {LokaliseAPI} = require('node-lokalise-api');
const api = new LokaliseAPI({token: '<your-lokalise-api-token>'});
const result = await api.screenshots.delete('abcde.12345', 567);
Snapshots
List all snapshots
const {LokaliseAPI} = require('node-lokalise-api');
const api = new LokaliseAPI({token: '<your-lokalise-api-token>'});
const result = await api.snapshots.list('<project id>', {page: 1, limit: 100});
Create a snapshot
const {LokaliseAPI} = require('node-lokalise-api');
const api = new LokaliseAPI({token: '<your-lokalise-api-token>'});
const result = await api.snapshots.create('<project id>', {
title: 'API snapshot'
});
Restore a snapshot
const {LokaliseAPI} = require('node-lokalise-api');
const api = new LokaliseAPI({token: '<your-lokalise-api-token>'});
const result = await api.snapshots.restore('<project id>', '<snapshot id>');
Delete a snapshot
const {LokaliseAPI} = require('node-lokalise-api');
const api = new LokaliseAPI({token: '<your-lokalise-api-token>'});
const result = await api.snapshots.delete('<project id>', '<snapshot id>');
Tasks
List all tasks
const {LokaliseAPI} = require('node-lokalise-api');
const api = new LokaliseAPI({token: '<your-lokalise-api-token>'});
const result = await api.tasks.list('<project id>', {page: 1, limit: 100});
Create a task
const {LokaliseAPI} = require('node-lokalise-api');
const api = new LokaliseAPI({token: '<your-lokalise-api-token>'});
const result = await api.tasks.create('<project id>', {
title: 'Voicemail messages',
description: 'Need your help with some voicemail message translation. Thanks!',
due_date: '2018-12-31 12:00:00 (Etc\/UTC)',
keys: [11212, 11241, 11245],
languages: [
{
language_iso: 'fi',
users: [421]
},
{
language_iso: 'ru',
users: [422]
}
],
auto_close_languages: true,
auto_close_task: true
});
Retrieve a task
const {LokaliseAPI} = require('node-lokalise-api');
const api = new LokaliseAPI({token: '<your-lokalise-api-token>'});
const result = await api.tasks.get('<project id>', '<task id>');
Update a task
const {LokaliseAPI} = require('node-lokalise-api');
const api = new LokaliseAPI({token: '<your-lokalise-api-token>'});
const result = await api.tasks.update('<project id>', '<task id>', {
due_date: '2019-12-31 12:00:00 (Etc\/UTC)',
auto_close_languages: false,
auto_close_task: false
});
Delete a task
const {LokaliseAPI} = require('node-lokalise-api');
const api = new LokaliseAPI({token: '<your-lokalise-api-token>'});
const result = await api.tasks.delete('<project id>', '<task id>');
Team Users
List all team users
const {LokaliseAPI} = require('node-lokalise-api');
const api = new LokaliseAPI({token: '<your-lokalise-api-token>'});
const result = await api.teamUsers.list('<team id>', {page: 1, limit: 100});
Retrieve a team user
const {LokaliseAPI} = require('node-lokalise-api');
const api = new LokaliseAPI({token: '<your-lokalise-api-token>'});
const result = await api.teamUsers.get('<team id>', '<user id>');
Update a team user
const {LokaliseAPI} = require('node-lokalise-api');
const api = new LokaliseAPI({token: '<your-lokalise-api-token>'});
const result = await api.teamUsers.update('<team id>', '<user id>', {
role: 'admin'
});
Delete a team user
const {LokaliseAPI} = require('node-lokalise-api');
const api = new LokaliseAPI({token: '<your-lokalise-api-token>'});
const result = await api.teamUsers.delete('<team id>', '<user id>');
Teams
List all teams
const {LokaliseAPI} = require('node-lokalise-api');
const api = new LokaliseAPI({token: '<your-lokalise-api-token>'});
const result = await api.teams.list({page: 1, limit: 100});
Translations
List all translations
const {LokaliseAPI} = require('node-lokalise-api');
const api = new LokaliseAPI({token: '<your-lokalise-api-token>'});
const result = await api.translations.list('<project id>', {page: 1, limit: 100});
Retrieve a translation
const {LokaliseAPI} = require('node-lokalise-api');
const api = new LokaliseAPI({token: '<your-lokalise-api-token>'});
const result = await api.translations.get('<project id>', '<translation id>');
Update a translation
const {LokaliseAPI} = require('node-lokalise-api');
const api = new LokaliseAPI({token: '<your-lokalise-api-token>'});
const result = await api.translations.update('<project id>', '<translation id>', {
translation: 'Quick brown fox jumps over the lazy dog.',
is_fuzzy: false,
is_reviewed: true
});
Development
Clone repository or its fork to local filesystem
git clone https://github.com/tormozz48/node-lokalise-api.git
Install npm dependencies:
npm install
Here are some suitable commands that can be used during development:
npm run build
- compile typescript filesnpm run docs
- create documentation based on jsdocsnpm run lint
- run tslint verification toolnpm run test
- run tests with mochanpm run cover
- calculate code test coverage with istanbulnpm run watch
- launch watcher for compile source files during development
License
Apache-2.0
Support
Bugs, PRs, comments, suggestions welcomed!