Lingo.dev CLI

0.133.9 · active · verified Wed Apr 22

Lingo.dev is an open-source i18n toolkit for Node.js environments, currently at version `0.133.9`, which is actively maintained with frequent patch releases addressing fixes and minor enhancements across its components. It functions as a comprehensive solution for localization, notably leveraging AI to streamline i18n setup in popular React frameworks like Next.js, React Router, and TanStack Start. A key differentiator is its 'MCP' (Multi-Context Planning) feature, which provides AI assistants with structured, framework-specific i18n knowledge to prevent common hallucination errors during setup. The package offers a robust CLI for translating various file formats (JSON, YAML, markdown, CSV, PO, VTT), an SDK for runtime translation, a compiler for build-time localization, and integrates into CI/CD pipelines. This ecosystem covers the full localization lifecycle from initial configuration to automated workflows.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates basic programmatic interaction with the Lingo.dev SDK for pushing and fetching JSON content, illustrating runtime translation capabilities.

import { Client } from 'lingo.dev';
import { readFileSync } from 'node:fs';

const lingoClient = new Client({
  apiKey: process.env.LINGO_API_KEY ?? '',
  projectId: process.env.LINGO_PROJECT_ID ?? '',
  baseUrl: 'https://api.lingo.dev'
});

async function translateContent() {
  if (!process.env.LINGO_API_KEY || !process.env.LINGO_PROJECT_ID) {
    console.error('LINGO_API_KEY and LINGO_PROJECT_ID environment variables must be set.');
    return;
  }

  try {
    // Example: Pushing content from a file (e.g., a simple JSON for translation)
    // In a real scenario, this would involve more complex file parsing.
    const sourceContent = readFileSync('src/locales/en.json', 'utf8');
    console.log('Pushing content for translation...');
    const pushResult = await lingoClient.pushJson({ 
        locale: 'en', 
        content: JSON.parse(sourceContent) 
    });
    console.log('Push result:', pushResult);

    // Example: Fetching translated content
    console.log('Fetching translations for es...');
    const translations = await lingoClient.fetchJson({
      locale: 'es',
      projectId: process.env.LINGO_PROJECT_ID ?? ''
    });
    console.log('Spanish Translations:', translations);

  } catch (error) {
    console.error('Error during Lingo.dev operation:', error);
  }
}

translateContent();

// To run the CLI (separate usage, typically from terminal):
// npx lingo.dev@latest run --help

view raw JSON →