Skip to content

JavaScript SDK

Add real-time AI-powered translations to your JavaScript applications with our easy-to-use SDK.

Perfect For

  • Chat Applications: Translate messages instantly
  • Email Clients: Localize incoming emails on-the-fly
  • Comment Systems: Make user content accessible in any language
  • Social Media Tools: Create multilingual experiences for global audiences

Installation

bash
npm install lingo.dev

Quick Setup

javascript
import { LingoDotDevEngine } from "lingo.dev/sdk";

const lingoDotDev = new LingoDotDevEngine({
  apiKey: "your-api-key-here",
});

Translation Methods

1. Translate Simple Text

javascript
const localizedText = await lingoDotDev.localizeText("Hello, world!", {
  sourceLocale: "en",
  targetLocale: "es",
});
// Result: "¡Hola Mundo!"

2. Translate to Multiple Languages at Once

javascript
const localizedTexts = await lingoDotDev.batchLocalizeText("Hello, world!", {
  sourceLocale: "en",
  targetLocales: ["es", "fr", "de"],
});
// Result: ['¡Hola Mundo!', 'Bonjour le monde!', 'Hallo Welt!']

3. Translate Objects

javascript
const localizedContent = await lingoDotDev.localizeObject(
  { greeting: "Hello", farewell: "Goodbye" },
  { sourceLocale: "en", targetLocale: "es" },
);
// Result: { greeting: "Hola", farewell: "Adiós" }

4. Translate Chat Conversations

javascript
const localizedChat = await lingoDotDev.localizeChat(
  [
    { name: "Alice", text: "Hello!" },
    { name: "Bob", text: "Hi there!" },
  ],
  { sourceLocale: "en", targetLocale: "es" },
);
// Result: [{ name: "Alice", text: "¡Hola!" }, { name: "Bob", text: "¡Hola!" }]

5. Translate HTML Content

javascript
const localizedHtml = await lingoDotDev.localizeHtml(
  "<div>Hello <strong>world</strong></div>",
  { sourceLocale: "en", targetLocale: "es" },
);
// Result: "<div>Hola <strong>mundo</strong></div>"

6. Detect Language

javascript
const locale = await lingoDotDev.recognizeLocale("Bonjour le monde");
// Result: 'fr'

Configuration Options

ParameterDescriptionDefaultMax
apiKeyYour Lingo.dev API keyRequired-
batchSizeMax items per API request50250
idealBatchItemSizeTarget word count per batch5002500
javascript
const lingoDotDev = new LingoDotDevEngine({
  apiKey: "your-api-key-here",
  batchSize: 100,
  idealBatchItemSize: 1000,
});

Translation Parameters

ParameterDescriptionRequired
sourceLocaleOriginal language code (e.g., 'en')Yes*
targetLocaleDesired language code (e.g., 'es')Yes
fastEnable faster translations (may reduce quality)No

*Can be set to null for automatic language detection

Speed vs. Quality Option

javascript
const quickTranslation = await lingoDotDev.localizeText("Hello world", {
  sourceLocale: "en",
  targetLocale: "es",
  fast: true, // Prioritize speed over quality
});

Automatic Language Detection

javascript
const localizedText = await lingoDotDev.localizeText("Hello, world!", {
  sourceLocale: null, // Auto-detect language
  targetLocale: "es",
});

Note: Auto-detection increases processing time. Use only when the source language is unknown (e.g., user-generated content).

Progress Tracking for Large Jobs

javascript
await lingoDotDev.localizeObject(
  largeObject,
  { sourceLocale: "en", targetLocale: "es" },
  (progress) => console.log(`Translation progress: ${progress}%`),
);

How It Works

The SDK optimizes translation performance through:

  1. Smart Chunking: Breaks content into optimal sizes for processing
  2. Progress Monitoring: Tracks completion percentage for user feedback
  3. Error Management: Handles API issues with automatic retries
  4. Response Assembly: Seamlessly recombines translated chunks

Best Practices

  1. Reuse Engine Instances: Create one instance and reuse it throughout your app
  2. Implement Error Handling: Add try/catch blocks around SDK calls
  3. Show Progress: Use callbacks for user feedback during large translations
  4. Optimize Content Structure: Flat objects perform better than deeply nested ones

With the Lingo.dev SDK, you can easily add powerful AI-driven translations to any JavaScript application, creating seamless multilingual experiences with minimal development effort.