XML

AI translation for XML files with Lingo.dev CLI

What is XML?

XML (Extensible Markup Language) is a markup language that defines rules for encoding documents in a format that is both human-readable and machine-readable. It's commonly used for configuration files, data exchange, and structured content.

For example:

<?xml version="1.0" encoding="UTF-8"?>
<root>
  <title>Hello, world!</title>

  <description>
    <summary>Simple demo app</summary>
    <details>Basic example content</details>
  </description>

  <image src="photo.jpg" alt="Example photo" title="Click to view"/>

  <link href="example.com" label="Click here">Learn more</link>

  <message>
    <greeting>Hello there!</greeting>
    <body>Welcome to the app</body>
  </message>
</root>

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 XML 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 XML 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.xml).

Step 5. Create a bucket

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

    {
      "$schema": "https://lingo.dev/schema/i18n.json",
      "version": "1.10",
      "locale": {
        "source": "en",
        "targets": ["es"]
      },
      "buckets": {
        "xml": {}
      }
    }
    
  2. In the "xml" 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": {
        "xml": {
          "include": ["./[locale]/example.xml"]
        }
      }
    }
    

    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.xml")
    • can use asterisks as wildcard placeholders (e.g., "[locale]/*.xml")

    Recursive glob patterns (e.g., **/*.xml) 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.xml

<?xml version="1.0" encoding="UTF-8"?>
<root>
  <title>Hello, world!</title>

  <description>
    <summary>Simple demo app</summary>
    <details>Basic example content</details>
  </description>

  <image src="photo.jpg" alt="Example photo" title="Click to view"/>

  <link href="example.com" label="Click here">Learn more</link>

  <button type="submit" value="Submit" placeholder="Enter text">Submit</button>

  <message>
    <greeting>Hello there!</greeting>
    <body>Welcome to the app</body>
    <signature>Thanks, MyApp Team</signature>
  </message>
</root>

es/example.xml

<?xml version="1.0" encoding="UTF-8"?>
<root>
  <title>¡Hola, mundo!</title>

  <description>
    <summary>Aplicación de demostración simple</summary>
    <details>Contenido de ejemplo básico</details>
  </description>

  <image src="photo.jpg" alt="Foto de ejemplo" title="Haz clic para ver"/>

  <link href="example.com" label="Haz clic aquí">Aprender más</link>

  <button type="submit" value="Enviar" placeholder="Ingresa texto">Enviar</button>

  <message>
    <greeting>¡Hola!</greeting>
    <body>Bienvenido a la aplicación</body>
    <signature>Gracias, Equipo de MyApp</signature>
  </message>
</root>

i18n.json

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

i18n.lock

version: 1
checksums:
  ec06a6ebae97ffd5f7afc99d9a8f051b:
    root/title: 0468579ef2fbc83c9d520c2f2f1c5059
    root/description/summary: f2c85bf6eeebeea33609e04598201bb6
    root/description/details: 2ee85b8f2f0f1bc008d9cf1f916cb09c
    root/image/%24/src: 3ce26f0a5486adf10e1b7eee1b866a70
    root/image/%24/alt: 94058fbed56fffaef2e9bbea59ba4a54
    root/image/%24/title: 60487c71b570d9dedca6fddd4a75d16a
    root/link/_: e598091d132f890c37a6d4ed94f6d794
    root/link/%24/href: 285d79d2783cf0769ab9e767362c1499
    root/link/%24/label: 26ce69aad587f70d47e7606436bf1d6d
    root/button/_: 7c91ef5f747eea9f77a9c4f23e19fb2e
    root/button/%24/type: fa8748b22d5bac98fdcd57e3d6594cf3
    root/button/%24/value: 7c91ef5f747eea9f77a9c4f23e19fb2e
    root/button/%24/placeholder: 7b5d59cee6952db66043a4b289b51884
    root/section/article/paragraph/sentence: 28ca53c71a2e3e3de79c892a9b193b1a
    root/meta/%24/name: d097029e873a4b19132e2603bd2c9fe4
    root/meta/%24/content: 0811ae3ab84aa87205383c3d8ac42bf3
    root/message/greeting: 85559fc839c5181b7958654e62c987d5
    root/message/body: ed0d4b1cde20d045f9f8c5007c784b0b
    root/message/signature: 181c8c304980949e101865098f548705