Internationalization
VitePress has built-in support for creating multilingual documentation sites with locale-specific configuration and content.Directory Structure
Organize content by language using locale-based directories:- Root Default
- Separate Directories
- Root is the default locale (e.g., English)
- Subdirectories for other languages
Basic Configuration
Configure locales in your VitePress config:The
lang attribute is added to the <html> tag for proper language detection by browsers and screen readers.Locale-Specific Configuration
Override site configuration per locale:1
Title and Description
2
Theme Configuration
3
Custom Head Tags
Configurable Properties
These properties can be overridden per locale:Property Details
Property Details
- lang: HTML language attribute (e.g.,
'en','es','zh-CN') - dir: Text direction (
'ltr'or'rtl') - title: Site title for this locale
- titleTemplate: Title format template
- description: Meta description
- head: Additional head tags (merged with global head)
- themeConfig: Theme configuration (shallow merged with global config)
Separate Directory Setup
When using separate directories for all locales, configure server redirects.Netlify Example
Createdocs/public/_redirects:
Using Language Cookie
Persist language choice with a cookie:Default Theme Localization
The default theme includes built-in text labels that can be localized:See the VitePress docs configuration for real examples:
docs/.vitepress/config.ts in the source repository.RTL (Right-to-Left) Support
For RTL languages like Arabic or Hebrew:1
Set Direction
2
Install PostCSS Plugin
3
Configure PostCSS
Organizing Multi-Locale Config
For better organization, split configuration by locale:Translation Workflow
1
Create Source Content
Write your content in the default language:
2
Duplicate Structure
Create the same structure for each locale:
3
Translate Content
Translate the content while preserving:
- File names (or update links accordingly)
- Frontmatter structure
- Internal link paths (add locale prefix)
4
Update Configuration
Add locale-specific navigation and sidebar
Best Practices
Maintain Consistent Structure
Maintain Consistent Structure
Keep the same file structure across all locales for easier maintenance:
Use Translation Keys
Use Translation Keys
For dynamic content, consider using a translation key system:
Test All Locales
Test All Locales
Ensure all locales build successfully:Check for:
- Broken internal links
- Missing translations
- Layout issues with longer text
- RTL rendering (if applicable)
Language Selector
The default theme automatically adds a language selector to the navigation when multiple locales are configured.Customizing the Selector
Control the selector appearance:Accessing Current Locale
In Vue components, access the current locale:SEO Considerations
1
hreflang Tags
Add alternate language tags:
2
Canonical URLs
Set canonical URLs to avoid duplicate content:
3
Sitemap
Generate locale-aware sitemaps: