Lingo.dev CLI
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
-
Error: Command not found: lingo.dev
cause The Lingo.dev CLI is not installed globally or `npx` is not resolving it correctly in your PATH.fixInstall the CLI globally (`npm install -g lingo.dev`) or use `npx lingo.dev@latest <command>` to execute it without global installation. -
Error: VTT parser crash on files with STYLE/REGION blocks
cause An older version of the Lingo.dev CLI had a bug in its VTT (WebVTT) parser when encountering `STYLE` or `REGION` blocks within the file.fixUpdate Lingo.dev to version `0.133.6` or newer, which contains a fix for this VTT parsing issue. -
Error: Authentication failed: Invalid API Key or Project ID.
cause The provided Lingo.dev API Key or Project ID is either missing, incorrect, or does not have sufficient permissions for the requested operation.fixVerify that your `LINGO_API_KEY` and `LINGO_PROJECT_ID` environment variables are correctly set and correspond to valid credentials for your Lingo.dev project. -
TypeError: Cannot read properties of undefined (reading 'pushJson')
cause This error likely occurs when attempting to call SDK methods on an uninitialized or incorrectly initialized `Client` instance, possibly due to missing configuration.fixEnsure the `Lingo.dev Client` is correctly instantiated with valid `apiKey`, `projectId`, and `baseUrl` in its configuration object.
Warnings
- breaking The package requires Node.js version 18 or higher. Older Node.js environments will fail to run the CLI or utilize the SDK.
- breaking SDK API error handling was changed to propagate network errors instead of silently treating them as 'not authenticated'. This means applications relying on previous silent failure behavior for network issues will now receive direct error throws.
- gotcha The documentation mentions `npm install lingo.dev` for SDK usage, but the internal SDK implementation is in `@lingo.dev/_sdk`. While the main `lingo.dev` package appears to re-export core SDK functionalities, direct imports from the internal `@lingo.dev/_sdk` package are not officially supported and may lead to issues or break in future versions.
- gotcha The CI pull request flow previously ignored existing translation branches and started from scratch, potentially creating duplicate PRs when original ones were merged concurrently.
Install
-
npm install lingo.dev -
yarn add lingo.dev -
pnpm add lingo.dev
Imports
- Client
const { Client } = require('lingo.dev');import { Client } from 'lingo.dev'; - LingoConfig
import { LingoConfig } from 'lingo.dev';import type { LingoConfig } from 'lingo.dev'; - run
import { run } from 'lingo.dev';import { run } from 'lingo.dev/cli';
Quickstart
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