JSON

AI translation for JSON files with Lingo.dev CLI

What is JSON?

JSON (JavaScript Object Notation) is a lightweight data-interchange format that is easy for humans to read and write and easy for machines to parse and generate. It is commonly used for configuration files, data storage, and API communication.

For example:

{
  "title": "Hello, world!",
  "description": "A simple demo app",
  "author": {
    "name": "John Doe"
  },
  "messages": [
    "Welcome to MyApp",
    "Hello, world!"
  ],
  "config": {
    "theme": {
      "primary": "Blue theme"
    }
  }
}

What is Lingo.dev CLI?

Lingo.dev CLI is a free, open-source CLI for translating apps and content with AI. It's designed to replace traditional translation management software while integrating with existing pipelines.

To learn more, see Overview.

About this guide

This guide explains how to translate JSON files with Lingo.dev CLI.

You'll learn how to:

  • Create a project from scratch
  • Configure a translation pipeline
  • Generate translations with AI

Prerequisites

To use Lingo.dev CLI, ensure that Node.js v18+ is installed:

❯ node -v
v22.17.0

Step 1. Set up a project

In your project's directory, create an i18n.json file:

{
  "$schema": "https://lingo.dev/schema/i18n.json",
  "version": "1.10",
  "locale": {
    "source": "en",
    "targets": ["es"]
  },
  "buckets": {}
}

This file defines the behavior of the translation pipeline, including what languages to translate between and where the localizable content exists on the file system.

To learn more about the available properties, see i18n.json.

Step 2. Configure the source locale

The source locale is the original language and region that your content was written in. To configure the source locale, set the locale.source property in the i18n.json file:

{
  "$schema": "https://lingo.dev/schema/i18n.json",
  "version": "1.10",
  "locale": {
    "source": "en",
    "targets": ["es"]
  },
  "buckets": {}
}

The source locale must be provided as a BCP 47 language tag.

For the complete list of the locale codes that Lingo.dev CLI supports, see Supported locale codes.

Step 3. Configure the target locales

The target locales are the languages and regions you want to translate your content into. To configure the target locales, set the locale.targets property in the i18n.json file:

{
  "$schema": "https://lingo.dev/schema/i18n.json",
  "version": "1.10",
  "locale": {
    "source": "en",
    "targets": ["es"]
  },
  "buckets": {}
}

Step 4. Create the source content

If you haven't already, create one or more JSON files that contain the content to be translated. These files must be located at a path that includes the source locale somewhere in the path (e.g., as a directory name like en/ or as part of the filename like messages.en.json).

Step 5. Create a bucket

  1. In the i18n.json file, add a "json" object to the buckets object:

    {
      "$schema": "https://lingo.dev/schema/i18n.json",
      "version": "1.10",
      "locale": {
        "source": "en",
        "targets": ["es"]
      },
      "buckets": {
        "json": {}
      }
    }
    
  2. In the "json" object, define an array of one or more include patterns:

    {
      "$schema": "https://lingo.dev/schema/i18n.json",
      "version": "1.10",
      "locale": {
        "source": "en",
        "targets": ["es"]
      },
      "buckets": {
        "json": {
          "include": ["./[locale]/example.json"]
        }
      }
    }
    

    These patterns define which files to translate.

    The patterns themselves:

    • must contain [locale] as a placeholder for the configured locale
    • can point to file paths (e.g., "[locale]/config.json")
    • can use asterisks as wildcard placeholders (e.g., "[locale]/*.json")

    Recursive glob patterns (e.g., **/*.json) are not supported.

Step 6. Configure an LLM

Lingo.dev CLI uses large language models (LLMs) to translate content with AI. To use one of these models, you need an API key from a supported provider.

To get up and running as quickly as possible, we recommend using Lingo.dev Engine — our own, hosted platform that offers 10,000 tokens of free, monthly usage:

  1. Sign up for a Lingo.dev account.

  2. Run the following command:

    npx lingo.dev@latest login
    

    This will open your default browser and ask you to authenticte.

  3. Follow the prompts.

Step 7. Generate the translations

In the directory that contains the i18n.json file, run the following command:

npx lingo.dev@latest run

This command:

  1. Reads the i18n.json file.
  2. Finds the files that need to be translated.
  3. Extracts the translatable content from the files.
  4. Uses the configured LLM to translate the extracted content.
  5. Writes the translated content back to the file system.

The first time translations are generated, an i18n.lock file is created. This file keeps track of what content has been translated, preventing unnecessary retranslations on subsequent runs.

Example

en/example.json

{
  "title": "Hello, world!",
  "description": "A simple demo app",
  "version": "1.0.0",
  "support_email": "[email protected]",
  "homepage": "https://lingo.dev",
  "deprecated": null,
  "empty": "",
  "emoji": "🚀",
  "author": {
    "name": "John Doe"
  },
  "contributors": [
    { "name": "Alice" },
    { "name": "Bob" }
  ],
  "messages": [
    "Welcome to MyApp",
    "Hello, world!"
  ],
  "config": {
    "theme": {
      "primary": "Blue theme"
    }
  },
  "mixed_array": [
    "Mixed content here",
    42,
    true,
    {
      "nested_message": "Nested text"
    }
  ],
  "locked_key_1": "This value is locked and should not be changed",
  "ignored_key_1": "This value is ignored and should not appear in target locales"
}

es/example.json

{
  "title": "¡Hola, mundo!",
  "description": "Una aplicación de demostración simple",
  "version": "1.0.0",
  "support_email": "[email protected]",
  "homepage": "https://lingo.dev",
  "deprecated": null,
  "empty": "",
  "emoji": "🚀",
  "author": {
    "name": "Juan Pérez"
  },
  "contributors": [
    { "name": "Alicia" },
    { "name": "Roberto" }
  ],
  "messages": [
    "Bienvenido a MyApp",
    "¡Hola, mundo!"
  ],
  "config": {
    "theme": {
      "primary": "Tema azul"
    }
  },
  "mixed_array": [
    "Contenido mixto aquí",
    42,
    true,
    {
      "nested_message": "Texto anidado"
    }
  ],
  "locked_key_1": "This value is locked and should not be changed"
}

i18n.json

{
  "version": "1.10",
  "locale": {
    "source": "en",
    "targets": ["es"]
  },
  "buckets": {
    "json": {
      "include": ["./[locale]/example.json"],
      "lockedKeys": ["locked_key_1"]
    }
  },
  "$schema": "https://lingo.dev/schema/i18n.json"
}

i18n.lock

version: 1
checksums:
  455da9346f4e772000927cd2ff5bb898:
    title: 0468579ef2fbc83c9d520c2f2f1c5059
    description: 49f8864eb0e53903f04532bf33e1e4fa
    version: 54a9e730e88fb16291b852274d433923
    support_email: 10627fcc465897af0f5e1bba042685f9
    emoji: b328c432cee108a87a92f05258b6a651
    author/name: febee8e9ab40b2fe5106d72675228d00
    contributors/0/name: e80d4063a32adaad7b0a82b0bcc10551
    contributors/1/name: b2bca2fa3c890618e56d07473f26ead3
    messages/0: d1c3a9f35e377554a4ccaa467ca26614
    messages/1: 0468579ef2fbc83c9d520c2f2f1c5059
    config/theme/primary: 7535a3779d6934ea8ecf18f5cb5b93fd
    mixed_array/0: 001b5b003d96c133534f5907abffdf77
    mixed_array/3/nested_message: 5f0782dfc5993e99890c0475bc295a30