Loco CLI

3.4.0 · active · verified Wed Apr 22

Loco CLI is a command-line interface tool designed to automate the synchronization of project translations with the Loco localization platform (localise.biz). It facilitates both pulling translations from Loco into your local project and pushing local changes back to Loco. The current stable version is 3.4.0, with a fairly active release cadence, frequently adding new features, improving types, and updating dependencies as seen in recent changelogs. A key differentiator is its focus as a Node.js-based solution, offering flexibility in configuration via `package.json` or various `.locorc` files, supporting both JSON and YAML formats, and now providing a dedicated documentation website. It aims to streamline the localization workflow for developers using JavaScript/TypeScript projects.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates programmatic execution of `loco-cli` commands ('pull' and 'push') within a TypeScript environment, including configuration loading and API key handling.

import { run } from 'loco-cli';
import path from 'node:path';

async function syncTranslations() {
  console.log('Starting translation sync...');
  try {
    // Example: Programmatically run the 'pull' command
    // This assumes `run` function can accept arguments programmatically.
    // In typical usage, you'd use 'npx loco-cli pull' from the terminal.
    await run(['pull', '--config', path.resolve(process.cwd(), '.locorc.js')], { 
      cwd: process.cwd(),
      // Pass environment variables or specific options needed by the CLI
      env: { LOCO_API_KEY: process.env.LOCO_API_KEY ?? '', ...process.env }
    });
    console.log('Translations pulled successfully!');

    // Example: Programmatically run the 'push' command with a specific tag
    await run(['push', '--tag', 'web-app', '--yes'], { 
      cwd: process.cwd(),
      env: { LOCO_API_KEY: process.env.LOCO_API_KEY ?? '', ...process.env }
    });
    console.log('Translations pushed successfully!');

  } catch (error) {
    console.error('Error during translation sync:', error);
    process.exit(1);
  }
}

syncTranslations();

view raw JSON →