Quick Start
This guide helps you quickly integrate internationalization into a Modern.js project.
Install the Plugin
i18next 和 react-i18next 是 Peer Dependency,需要手动安装。
版本一致性
@modern-js/plugin-i18n 需要与项目中 @modern-js/app-tools 版本保持一致。
Basic Configuration
Step 1: Register the Plugin
Register the plugin in modern.config.ts:
Step 2: Create Translation Files
Resource loading
By default, the plugin looks for translation resources in the specified local directory. More resource loading methods are covered in later chapters.
Create the config/public/locales directory:
Step 3: Configure Runtime Options
创建 src/modern.runtime.ts:
Step 4: Use It in Components
Text returned by the t() function updates automatically after changeLanguage is called. No manual refresh is required.
Next Steps
Choose what to read next based on your needs:
- Want a URL structure like
/en/about-> Routing Integration - Need automatic language switching based on Cookie / Header -> Locale Detection
- Translation resources come from a remote service -> Resource Loading -> Custom Backend
- SSR scenarios -> Advanced Usage
- View all configuration options -> Configuration