Options
All
  • Public
  • Public/Protected
  • All
Menu

node-lokalise-api

node-lokalise-api

Simple NodeJS wrapper around Lokalise service.

npm license travis status Coverage Status David David Commitizen friendly
NPM

Localise API documentation can be found here

Detail package documentation can be found here

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 Lokalize
  • timeout - 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

Documentation

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

Documentation

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

Documentation

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

Documentation

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

Documentation

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

Documentation

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

Documentation

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: 'translator@mycompany.com',
            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

Documentation

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

Documentation

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

Documentation

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

Documentation

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

Documentation

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

Documentation

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

Documentation

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

Documentation

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

Documentation

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

Documentation

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

Documentation

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

Documentation

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

Documentation

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

Documentation

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

Documentation

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

Documentation

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

Documentation

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

Documentation

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

Documentation

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

Documentation

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

Documentation

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

Documentation

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

Documentation

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

Documentation

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

Documentation

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

Documentation

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

Documentation

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

Documentation

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

Documentation

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

Documentation

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

Documentation

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

Documentation

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

Documentation

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

Documentation

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

Documentation

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

Documentation

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

Documentation

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

Documentation

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

Documentation

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

Documentation

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

Documentation

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

Documentation

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

Documentation

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

Documentation

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

Documentation

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

Documentation

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

Documentation

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 files
  • npm run docs - create documentation based on jsdocs
  • npm run lint - run tslint verification tool
  • npm run test - run tests with mocha
  • npm run cover - calculate code test coverage with istanbul
  • npm run watch - launch watcher for compile source files during development

License

Apache-2.0

Support

Bugs, PRs, comments, suggestions welcomed!

Generated using TypeDoc