MDX Translation
MDX combines the power of Markdown with JSX, allowing you to use React components within your content. Lingo.dev offers specialized support for MDX files, optimizing the translation process while preserving component structure and functionality.
Use Cases
- Interactive documentation
- Technical content with embedded components
- Help centers with UI elements
- Blog posts with interactive elements
- Educational content with embedded examples
How Lingo.dev Handles MDX
Lingo.dev's approach to MDX translation is designed for efficiency and precision:
Deep Structure Analysis
Unlike simple text-based translation (like Markdown), Lingo.dev:
- Deeply destructures MDX content - We parse the MDX into an Abstract Syntax Tree (AST), allowing us to understand the structure beyond just text.
- Preserves component integrity - JSX components and their props remain untouched during translation.
- Translates only content nodes - Only the actual content gets translated, not code or component definitions.
Caching
Our caching mechanism is designed to save time and resources:
- Element-level caching - If you change just one word in a paragraph, only that element gets retranslated, not the entire file.
- Structural fingerprinting - We identify elements by their structure and position, enabling precise updates.
- Differential processing - Only modified content triggers new translations.
Cost Optimization
Lingo.dev is designed to be cost-effective:
- Selective localization - Technical elements, code blocks, and component definitions aren't sent for translation, saving tokens and costs.
- Smart token usage - We optimize the content sent to language models to reduce unnecessary token consumption.
- Translation memory - Previously translated content is reused when possible (when Lingo.dev-managed localization is used).
TIP
By not localizing code elements and technical content that should remain unchanged, users can save significant costs in tokens and processing time.
Setting Up
Configure your i18n.json
to include MDX files:
{
"version": 1,
"locale": {
"source": "en",
"targets": ["es", "fr", "de"]
},
"buckets": {
"mdx": {
"include": ["docs/[locale]/*.mdx"]
}
}
}
Technical Implementation
Lingo.dev uses a parser chain that:
- Parses MDX into an AST
- Analyzes the structure to identify translatable content
- Sends only the relevant parts for translation
- Reconstructs the MDX with translated content while preserving structure
This approach ensures your components continue to work properly after translation, with no changes to functionality.
Best Practices
- Keep component props simple - Complex nested JSX in props may affect translation quality
- Use semantic component names - Clear names help the translation engine understand context
- Test interactive elements - Always verify that interactive components work after translation
Integration with Other Features
MDX translation works seamlessly with other Lingo.dev features:
- Fine-tuning for specialized technical terminology
- Overriding for manual edits to translations
- Translation caching for improved performance
- Key locking for protecting sensitive content
Example
Here's how a simple MDX file with components might be handled:
---
title: Interactive Tutorial
---
# Getting Started with Components
This is a simple paragraph explaining the concept.
<CodeExample language="javascript">
function hello() {
console.log("Hello, world!");
}
</CodeExample>
The above code demonstrates a basic function. <Highlight>Try it yourself!</Highlight>
<InteractiveDemo initialValue={42} />
When translated, only the actual content text gets processed while preserving the component structure and code.
TIP
If you encounter an MDX use case that we don't support, please email us immediately at [email protected]. For simpler MDX content, you can also try using the standard Markdown format, which supports basic MDX on a fundamental level. This dedicated MDX format is our specialized, advanced solution for complex MDX content with interactive components.
Learn More
- Markdown Translation - Basic markdown translation features
- Fine-tuning - Custom training for your technical terminology
- Overriding - Making manual edits to translations
- Translation Caching - Optimizing translation performance