YAML
AI translation for YAML files with Lingo.dev CLI
What is YAML?
YAML (YAML Ain't Markup Language) is a human-readable data serialization format commonly used for configuration files, data exchange, and structured data storage. It uses indentation to represent hierarchy and supports complex data structures.
For example:
title: "MyApp"
description: Hello, world!
welcome_message: 'Welcome to MyApp'
user_profile:
display_name: "John Doe"
bio: Software developer
navigation_items:
- "Home"
- "About"
- "Contact"
product:
name: "MyWidget"
tagline: The best widget ever
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 YAML 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 YAML 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.yml).
Step 5. Create a bucket
-
In the
i18n.jsonfile, add a"yaml"object to thebucketsobject:{ "$schema": "https://lingo.dev/schema/i18n.json", "version": "1.10", "locale": { "source": "en", "targets": ["es"] }, "buckets": { "yaml": {} } } -
In the
"yaml"object, define an array of one or moreincludepatterns:{ "$schema": "https://lingo.dev/schema/i18n.json", "version": "1.10", "locale": { "source": "en", "targets": ["es"] }, "buckets": { "yaml": { "include": ["./[locale]/example.yml"] } } }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.yml") - can use asterisks as wildcard placeholders (e.g.,
"[locale]/*.yml")
Recursive glob patterns (e.g.,
**/*.yml) are not supported. - must contain
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:
-
Run the following command:
npx lingo.dev@latest loginThis will open your default browser and ask you to authenticte.
-
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:
- Reads the
i18n.jsonfile. - Finds the files that need to be translated.
- Extracts the translatable content from the files.
- Uses the configured LLM to translate the extracted content.
- 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.yml
title: "MyApp"
description: Hello, world!
welcome_message: 'Welcome to MyApp'
user_profile:
display_name: "John Doe"
bio: Software developer
navigation_items:
- "Home"
- "About"
- "Contact"
product:
name: "MyWidget"
tagline: The best widget ever
features:
- "Easy to use"
- "Fast and reliable"
settings:
max_users: 100
enabled: true
timeout: 30.5
complex_structure:
level_one:
level_two:
message: "Deep 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.yml
title: "MyApp"
description: "¡Hola, mundo!"
welcome_message: "Bienvenido a MyApp"
user_profile:
display_name: "Juan Pérez"
bio: "Desarrollador de software"
navigation_items:
- "Inicio"
- "Acerca de"
- "Contacto"
product:
name: "MyWidget"
tagline: "El mejor widget de todos"
features:
- "Fácil de usar"
- "Rápido y confiable"
settings:
max_users: 100
enabled: true
timeout: 30.5
complex_structure:
level_one:
level_two:
message: "Texto anidado profundo"
locked_key_1: "This value is locked and should not be changed"
i18n.json
{
"$schema": "https://lingo.dev/schema/i18n.json",
"version": "1.10",
"locale": {
"source": "en",
"targets": ["es"]
},
"buckets": {
"yaml": {
"include": ["./[locale]/example.yml"],
"lockedKeys": ["locked_key_1"]
}
}
}
i18n.lock
version: 1
checksums:
1b0d7c9f07dcc31a978bc337763270ea:
title: 7dc70110429d46e3685f385bd2cc941c
description: 0468579ef2fbc83c9d520c2f2f1c5059
welcome_message: d1c3a9f35e377554a4ccaa467ca26614
user_profile/display_name: febee8e9ab40b2fe5106d72675228d00
user_profile/bio: 155ddcb7c93493ac72a37074eea0a653
navigation_items/0: 104a3db3b671c04e167eafbe21e57881
navigation_items/1: 944521eeeed2511833d2299931273c71
navigation_items/2: 9afa39bc47019ee6dec6c74b6273967c
product/name: ed21de171d538a49db999c47875f75a5
product/tagline: b7ac41680e82d75ae7f5774f7ceef1b4
product/features/0: c916ba887951a02793ff851853fd964f
product/features/1: 1c60a04d6890c6ec910a7f2e6ec0ae7b
complex_structure/level_one/level_two/message: b53034560bf657106e5aaea9160e357e