DatoCMS Integration
Replexica 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 Replexica localization engine memory across multiple projects.
Prerequisites
Before setting up Replexica 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
"project": "146425",
// Model ID from Settings > Models > [Your Model] > Settings
"model": "documentation_page",
// Optional: Specific record IDs to translate
// Find these in the URL when editing a record
"records": [
"185834003"
],
// Field IDs from your model's configuration
// These are the API identifiers visible in the model builder
"fields": [
"title",
"subtitle",
"content"
]
}
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/documentation_page.json5",
"demo/dato/change_log.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 replexica@latest i18n
Replexica 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", "model": "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{ "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 replexica@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.