MJML
AI translation for MJML email templates with Lingo.dev CLI
What is MJML?
MJML (Mailjet Markup Language) is a responsive email framework that makes it easy to create responsive email templates. It uses a semantic syntax that simplifies the development of responsive emails and compiles to standard HTML that works across all major email clients.
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 MJML email templates 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 MJML template 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 example_en.mjml).
For MJML templates, translatable content includes:
- Text content within MJML components:
mj-text(body text)mj-button(button labels)mj-title(email title in preview)mj-preview(preview text)mj-navbar-link(navigation links)mj-accordion-title(accordion headings)mj-accordion-text(accordion content)
- HTML elements within MJML:
p,h1-h6,li - Attribute values including:
altandtitleattributes onmj-imagetitleandaria-labelattributes onmj-buttontitleandaltattributes onmj-social-elementaltandtitleattributes on HTMLimgandaelements
How inline HTML is handled:
When text contains inline HTML elements (such as <strong>, <span>, <em>, <a>, etc.), the entire text block is translated as one complete unit. This preserves context for better translation quality and maintains inline formatting.
For example:
<mj-text>
<p>Welcome to <strong>our platform</strong>!</p>
</mj-text>
The entire paragraph "Welcome to <strong>our platform</strong>!" is translated as a single block, keeping the <strong> tags in place. This ensures the AI translator has full context and inline formatting is preserved in the translation.
Template variables (like Razor variables @Model.UserName) are preserved during translation.
Step 5. Create a bucket
-
In the
i18n.jsonfile, add an"mjml"object to thebucketsobject:{ "$schema": "https://lingo.dev/schema/i18n.json", "version": "1.10", "locale": { "source": "en", "targets": ["es"] }, "buckets": { "mjml": {} } } -
In the
"mjml"object, define an array of one or moreincludepatterns:{ "$schema": "https://lingo.dev/schema/i18n.json", "version": "1.10", "locale": { "source": "en", "targets": ["es"] }, "buckets": { "mjml": { "include": ["./[locale]/example.mjml"] } } }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]/example.mjml") - can use asterisks as wildcard placeholders (e.g.,
"[locale]/*.mjml")
Recursive glob patterns (e.g.,
**/*.mjml) 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:
-
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.mjml
<?xml version="1.0" encoding="UTF-8"?>
<mjml>
<mj-head>
<mj-title>Welcome to Our Service</mj-title>
<mj-preview>Get started with your new account today</mj-preview>
<mj-attributes>
<mj-all font-family="Arial, sans-serif" />
</mj-attributes>
</mj-head>
<mj-body>
<mj-section background-color="#f0f0f0">
<mj-column>
<mj-image
src="https://example.com/logo.png"
alt="Company Logo"
width="150px"
/>
</mj-column>
</mj-section>
<mj-section background-color="#ffffff" padding="20px">
<mj-column>
<mj-text font-size="24px" color="#333333" font-weight="bold">
Welcome to Our Platform!
</mj-text>
<mj-text font-size="16px" color="#555555" line-height="24px">
Thank you for signing up. We're excited to have you on board.
</mj-text>
<mj-text font-size="16px" color="#555555" line-height="24px">
To get started, please verify your email address by clicking the
button below.
</mj-text>
</mj-column>
</mj-section>
<mj-section background-color="#ffffff" padding="20px">
<mj-column>
<mj-button
background-color="#007bff"
color="#ffffff"
href="https://example.com/verify"
title="Verify your email address"
aria-label="Verify email"
>
Verify Email Address!
</mj-button>
</mj-column>
</mj-section>
<mj-section background-color="#ffffff" padding="20px">
<mj-column>
<mj-text font-size="14px" color="#666666">
If you didn't create an account, you can safely ignore this email.
</mj-text>
<mj-text font-size="14px" color="#666666">
Need help? Contact our support team.
</mj-text>
</mj-column>
</mj-section>
<mj-section background-color="#f8f9fa" padding="20px">
<mj-column>
<mj-social mode="horizontal">
<mj-social-element
name="facebook"
href="https://facebook.com/example"
title="Follow us on Facebook"
alt="Facebook"
/>
<mj-social-element
name="twitter"
href="https://twitter.com/example"
title="Follow us on Twitter"
alt="Twitter"
/>
<mj-social-element
name="instagram"
href="https://instagram.com/example"
title="Follow us on Instagram"
alt="Instagram"
/>
</mj-social>
<mj-text font-size="12px" color="#999999" align="center">
© 2024 Example Company. All rights reserved.
</mj-text>
</mj-column>
</mj-section>
</mj-body>
</mjml>
es/example.mjml
<?xml version="1.0" encoding="UTF-8"?>
<mjml>
<mj-head>
<mj-title>Bienvenido a nuestro servicio</mj-title>
<mj-preview>Comienza con tu nueva cuenta hoy</mj-preview>
<mj-attributes>
<mj-all font-family="Arial, sans-serif" />
</mj-attributes>
</mj-head>
<mj-body>
<mj-section background-color="#f0f0f0">
<mj-column>
<mj-image
src="https://example.com/logo.png"
alt="Logo de la empresa"
width="150px"
/>
</mj-column>
</mj-section>
<mj-section background-color="#ffffff" padding="20px">
<mj-column>
<mj-text font-size="24px" color="#333333" font-weight="bold">
¡Bienvenido a nuestra plataforma!
</mj-text>
<mj-text font-size="16px" color="#555555" line-height="24px">
Gracias por registrarte. Estamos encantados de tenerte con nosotros.
</mj-text>
<mj-text font-size="16px" color="#555555" line-height="24px">
Para comenzar, por favor verifica tu dirección de correo electrónico
haciendo clic en el botón de abajo.
</mj-text>
</mj-column>
</mj-section>
<mj-section background-color="#ffffff" padding="20px">
<mj-column>
<mj-button
background-color="#007bff"
color="#ffffff"
href="https://example.com/verify"
title="Verifica tu dirección de correo electrónico"
aria-label="Verificar correo"
>
¡Verificar dirección de correo!
</mj-button>
</mj-column>
</mj-section>
<mj-section background-color="#ffffff" padding="20px">
<mj-column>
<mj-text font-size="14px" color="#666666">
Si no creaste una cuenta, puedes ignorar este correo electrónico.
</mj-text>
<mj-text font-size="14px" color="#666666">
¿Necesitas ayuda? Contacta a nuestro equipo de soporte.
</mj-text>
</mj-column>
</mj-section>
<mj-section background-color="#f8f9fa" padding="20px">
<mj-column>
<mj-social mode="horizontal">
<mj-social-element
name="facebook"
href="https://facebook.com/example"
title="Síguenos en Facebook"
alt="Facebook"
/>
<mj-social-element
name="twitter"
href="https://twitter.com/example"
title="Síguenos en Twitter"
alt="Twitter"
/>
<mj-social-element
name="instagram"
href="https://instagram.com/example"
title="Síguenos en Instagram"
alt="Instagram"
/>
</mj-social>
<mj-text font-size="12px" color="#999999" align="center">
© 2024 Example Company. Todos los derechos reservados.
</mj-text>
</mj-column>
</mj-section>
</mj-body>
</mjml>
i18n.json
{
"$schema": "https://lingo.dev/schema/i18n.json",
"version": "1.10",
"locale": {
"source": "en",
"targets": ["es"]
},
"buckets": {
"mjml": {
"include": ["./[locale]/example.mjml"]
}
}
}
i18n.lock
version: 1
checksums:
c1acde0589961652d4caf8a39d080857:
mjml/mj-head/0/mj-title/0: c514a686b50f7158b2dd08ea65d3bc8a
mjml/mj-head/0/mj-preview/0: 4ce14f6062c814cbdcdf8b0a3cb094d3
mjml/mj-body/0/mj-section/0/mj-column/0/mj-image/0#alt: 82d5c0d5994508210ee02d684819f4b8
mjml/mj-body/0/mj-section/1/mj-column/0/mj-text/0: b320b02942617a70dcbd1beac61da11a
mjml/mj-body/0/mj-section/1/mj-column/0/mj-text/1: 028311348a5aeefea365fdf422a3fb21
mjml/mj-body/0/mj-section/1/mj-column/0/mj-text/2: 0dfdc9b80ee70fcc2b28d0e81e03fabc
mjml/mj-body/0/mj-section/2/mj-column/0/mj-button/0#title: 5c96f738bd6153ee07b72094cdfd2b98
mjml/mj-body/0/mj-section/2/mj-column/0/mj-button/0#aria-label: 42dcab68d931f9145d9b6d76740a5c66
mjml/mj-body/0/mj-section/2/mj-column/0/mj-button/0: dc8001d5c58294d22fe0b0e6118dbfb7
mjml/mj-body/0/mj-section/3/mj-column/0/mj-text/0: a18f14ab69467cbdbe467df6255cfda7
mjml/mj-body/0/mj-section/3/mj-column/0/mj-text/1: e83236e98aad1937bc99a47cff159caa
mjml/mj-body/0/mj-section/4/mj-column/0/mj-social/0/mj-social-element/0#title: 180bd8aa700f6cedf65e0a2079503cea
mjml/mj-body/0/mj-section/4/mj-column/0/mj-social/0/mj-social-element/0#alt: ac8afe226a7424849c247e6a9d566f64
mjml/mj-body/0/mj-section/4/mj-column/0/mj-social/0/mj-social-element/1#title: ea4c2a7a9a60cbb0f8f9632222a46abe
mjml/mj-body/0/mj-section/4/mj-column/0/mj-social/0/mj-social-element/1#alt: ba3d4aed69a50759b53a0b7c319a3ad9
mjml/mj-body/0/mj-section/4/mj-column/0/mj-social/0/mj-social-element/2#title: 754efa5f98f51c510ff268e217877d8b
mjml/mj-body/0/mj-section/4/mj-column/0/mj-social/0/mj-social-element/2#alt: c9555810826c30d571ffae869a236494
mjml/mj-body/0/mj-section/4/mj-column/0/mj-text/0: 9ac6c625c7af33d70634846c8c9d11b0