🇬🇧 English | 🇪🇸 Español | ru Russian
vite-plugin-i18n-json-md
is a Vite plugin that significantly facilitates the internationalization of an application. It allows translating text in JSON5 and Markdown formats into the standard JSON format for i18n files.
This simplifies the process of translating text and enhances collaboration between developers and translators.
Using AI to translate these text files accelerates the translation process and improves the quality of translations without the need for additional tools.
- JSON5 Support: Use JSON5 for your translation files, allowing for comments and more readable syntax.
- Markdown Integration: Write translations in Markdown, making it easier to handle complex text formatting.
- Automatic Compilation: Automatically compile your JSON5 and Markdown files into standard JSON files for use in your application.
- Vite Integration: Seamlessly integrates with Vite, ensuring fast and efficient builds.
To install the plugin, use npm, yarn, or pnpm:
npm install vite-plugin-i18n-json-md --save-dev
yarn add vite-plugin-i18n-json-md --dev
pnpm add vite-plugin-i18n-json-md --dev
The plugin provides comprehensive configuration options to customize your internationalization workflow:
- Type:
string
- Description: The directory where your source translation files are located. Subdirectories of the corresponding locale will be processed as well.
- Example:
'src/locales'
- Type:
string
- Description: The directory where compiled translation files will be generated.
- Example:
'src/assets/i18n'
- Type:
string[]
- Description: An array of locale strings to process. These are treated as subdirectories within the
sourceDir
. - Example:
['en', 'es', 'zh-CN']
- Type:
"dev" | "prod" | "both" | "off"
- Default:
"both"
- Description: Determines in which environment the plugin operates.
"dev"
: Only active during development"prod"
: Only active during production build"both"
: Active in both development and production"off"
: Plugin is disabled
- Type:
boolean
- Default:
false
- Description: Whether to minify the output translation files.
- Type:
"json" | "json5" | "js"
- Default:
"json"
- Description: The format of the generated translation files.
Here's a configuration example:
import { defineConfig } from 'vite';
import { jsonMdPlugin } from 'vite-plugin-i18n-json-md';
export default defineConfig({
plugins: [
jsonMdPlugin({
sourceDir: 'src/locales',
outputDir: 'src/assets/i18n',
locales: ['en', 'fr', 'es'],
mode: 'both',
minify: true,
outputFormat: 'json'
})
]
});
The plugin supports two main ways of processing markdown:
Use the md:
prefix to process inline markdown directly in your JSON5 files:
{
"welcome": {
"title": "md:# Welcome to our platform",
"description": "md:We offer:\n\n- Feature One\n- Feature Two\n- Feature Three"
}
}
Use the md:@
prefix to include external markdown files. Can use subdirectories:
{
"welcome": {
// Will look for `src/locales/en/legal/privacy-policy.md` if sourceDir is `src/locales` and locale is `en`
"privacyPolicy": "md:@legal/privacy-policy.md"
}
}
{
// Welcome section with markdown formatting and external markdown
"title": "md:# Welcome to **Our Platform**",
"subtitle": "md:Discover *amazing* features and possibilities",
"features": "md:@md/features.md",
"description": "A comprehensive platform for modern developers",
"callToAction": {
"text": "md:**[Get Started Now →](https://example.com/signup)**",
"style": "primary"
}
}
{
// User-related messages with mixed content
"greeting": "Hello, {name}!",
"profile": {
"complete_profile": "md:*Complete your profile* to unlock **all features**"
}
}
## Our Key Features
- 🚀 High Performance Rendering
- 💡 Innovative Design Patterns
- 🔒 Advanced Security Protocols
- 🌐 Multi-language Support
- ⚡ Lightning Fast Compilation
{
"title": "<h1>Welcome to <strong>Our Platform</strong></h1>",
"subtitle": "<p>Discover <em>amazing</em> features and possibilities</p>",
"features": "<h2>Our Key Features</h2>\n<ul>\n<li>🚀 High Performance Rendering</li>\n<li>💡 Innovative Design Patterns</li>\n<li>🔒 Advanced Security Protocols</li>\n<li>🌐 Multi-language Support</li>\n<li>⚡ Lightning Fast Compilation</li>\n</ul>",
"description": "A comprehensive platform for modern developers",
"callToAction": {
"text": "<p><strong><a href=\"https://example.com/signup\">Get Started Now →</a></strong></p>",
"style": "primary"
},
"greeting": "Hello, {name}!",
"profile": {
"complete_profile": "<p><em>Complete your profile</em> to unlock <strong>all features</strong></p>"
}
}
- Separate complex content into dedicated markdown files
- Easy translate the markdown files using AI tools
- Keep translations organized and modular
- Use
md:
prefix for markdown content - Combine plain text and markdown seamlessly
- Leverage HTML formatting for rich translations
- Keep translations readable and maintainable
MIT License