Skip to main content

Localang.xyz Push/Pull Helpers

Also, to automate translation synchronization between localang.xyz and your codebase, you can use special halpers to upload and download translations from localang.xyz.

Push

You can use push to upload translations.

Helper will upload translations to localang.xyz.

import { push } from 'localang-i18n-js';

/**
* @type {string}
* @see https://docs.localang.xyz/docs/localang/api#obtaining-a-token
*/
const authToken = 'your-auth-token';
/**
* @type {number}
* @see https://docs.localang.xyz/docs/localang/api#project-id
*/
const projectId = 1;
/**
* Files with translations must be generated by ESLint plugin (https://docs.localang.xyz/docs/i18n-js/i18n-file-generator).
* @type {string[]}
*/
const files = [
'src/index.i18n.ts',
'src/components/Header.i18n.ts',
'src/components/Footer.i18n.ts',
];

push(authToken, projectId, files);

Pull

You can use pull to download translations.

The helper will load the translations and update the local files relative to the project root.

import { pull } from 'localang-i18n-js';

/**
* @type {string}
* @see https://docs.localang.xyz/docs/localang/api#obtaining-a-token
*/
const authToken = 'your-auth-token';
/**
* @type {number}
* @see https://docs.localang.xyz/docs/localang/api#project-id
*/
const projectId = 1;

pull(authToken, projectId);