DatoCMS Integration
Lingo.dev seamlessly integrates with DatoCMS. This integration enables automated localization of your content directly through the DatoCMS API. Unlike local file formats, it works with remotely stored data. This makes it perfect for reusing existing Lingo.dev localization engine memory across multiple projects.
Prerequisites
Before setting up Lingo.dev integration, you need to enable localization in your DatoCMS project:
- Go to your DatoCMS account, select your project, then navigate to "Configuration" > "Locales and Timezones" (or visit the configuration/locales-and-timezone URL directly);
- Select the languages you want to support;
- Set your primary language - it should go first in the list (this should match the
source
in youri18n.json
).
Understanding DatoCMS Concepts
Before setting up, let's understand the key DatoCMS concepts:
Project: Your DatoCMS workspace where all your content lives. Each project has a unique ID that you can find in your project's URL or Settings > Project Settings.
Model: A content type definition in DatoCMS (like "Blog Post", "Product", or "Documentation Page"). Models define the structure of your content. Find model IDs in Settings > Models > [Your Model] > Settings tab.
Record: An individual piece of content created from a model (like a specific blog post or product). Each record has a unique ID visible in its URL when editing.
Field: A specific content attribute in a model (like "title", "description", or "content"). Field IDs are the API identifiers visible in the model builder interface.
Setting Up
Create a configuration file in your project. Here's an example with explanations:
{
// Project ID from Settings > Project Settings (required)
project: "146425",
// Optional: Configure models to translate
models: {
// Model ID as the key
documentation_page: {
// Optional: Specific record IDs to translate
records: ["185834003"],
// Optional: Field IDs to translate
fields: ["title", "subtitle", "content"],
},
blog_post: {
fields: ["title", "content"],
},
},
}
Only the project
field and DATO_API_TOKEN
environment variable are required. The models
configuration will be automatically updated when you use the CLI's interactive mode to select content for translation.
The configuration structure means:
project
: Your DatoCMS project IDmodels
: A map of model IDs to their translation settings- Each model can specify optional
records
(specific content to translate) - Each model can specify optional
fields
(which fields to translate)
- Each model can specify optional
Important
Both your DatoCMS configuration file and the generated i18n.lock
lockfile must be committed to version control. The lockfile tracks translation states and ensures consistency across your team.
While the DATO_API_TOKEN
should be kept secure in environment variables, all other configuration files should be tracked in git.
Configuration in i18n.json
Add the DatoCMS configuration to your i18n.json
:
{
"version": 1.2,
"locale": {
"source": "en",
"targets": ["es", "fr", "de"]
},
"buckets": {
"dato": {
"include": ["demo/dato/config.json5"]
}
}
}
Authentication
Get your DatoCMS API token:
Go to Settings > API tokens in your DatoCMS project
Create a new full-access API token
Set it up in one of two ways:
Option 1: Environment Variable
bashexport DATO_API_TOKEN=your_api_token_here
Option 2: .env File Create a
.env
file in your project root:envDATO_API_TOKEN=your_api_token_here
Running Translations
With your configuration set, run:
npx lingo.dev@latest i18n
Lingo.dev will:
- Connect to your DatoCMS project
- Enable localization for specified fields if not already enabled
- Fetch content from the source language
- Translate to target languages
- Push translations back to DatoCMS
Supported Content Types
The integration supports two types of content:
- String Fields: Simple text fields like titles, descriptions, or metadata
- Structured Text (DAST): DatoCMS's rich text format, including:
- Paragraphs
- Headers
- Lists
- Rich text formatting
- Links
- Embedded content
Pro Tips
Selective Translation: Use the
records
field to translate specific content:json5{ project: "146425", models: { documentation_page: { // We support JSON5 format, so you can add descriptive comments // for better maintainability and documentation records: [ "185834003", // Homepage content "185834004", // About us page "185834005", // Product documentation ], fields: ["title", "content"], }, }, }
Field Selection: Only specify fields that need translation:
json5{ project: "146425", models: { documentation_page: { fields: [ "title", // Translate this "content", // And this // "created_at" // But not this ], }, }, }
Quality Control: Use interactive mode for reviewing translations of critical content
Frozen Mode: Use
--frozen
to ensure content hasn't changed:bashnpx lingo.dev@latest i18n --frozen
Error Handling
The integration includes robust error handling:
- Invalid API keys
- Missing permissions
- Network issues
- Invalid field configurations
Each error includes detailed information to help you resolve the issue quickly.
Best Practices
- Version Control: Keep your DatoCMS configuration files in version control
- API Token Security: Never commit your
DATO_API_TOKEN
- use environment variables - Regular Updates: Run translations regularly to keep content in sync
- Testing: Test translations on staging before applying to production content
- Field Setup: Ensure fields are properly configured for localization in DatoCMS
- Content Modeling: Design your content models with translation in mind
By leveraging these features, you can maintain a robust, automated localization workflow for your DatoCMS content. The integration handles the complexity of API interactions, allowing you to focus on content creation while ensuring your content reaches a global audience.
Known Limitations
When working with rich text content in DatoCMS (e.g. article content, blog posts, etc.), the structure of the target language content must match the source content structure before running the Lingo.dev translation command. This means:
- Target language content should not be empty
- Target language content should maintain the same paragraphs, images, and styling as the source
- Removing or modifying structural elements in target languages will cause issues
By default, DatoCMS automatically copies the source language content to target languages when localization is enabled, so this shouldn't be a significant concern.
However, if you find this workflow suboptimal for your use case, please reach out to [email protected], and we will suggest alternative approaches. 👌