Internationalization

@modern-js/plugin-i18n 是 Modern.js 的国际化插件,基于 i18nextreact-i18next 构建。

  • 插件本身:负责与 Modern.js 框架的集成,如 SSR 语言传递、路由前缀处理等
  • i18next:核心翻译能力,如 t() 函数、插值、复数、命名空间。
  • react-i18next:React 组件和 Hook,如 useTranslation,实现与 React 生命周期的结合。

Where to start?

What you want to doDocumentation
Integrate for the first time and run an exampleQuick Start
Learn all configuration optionsConfiguration
Detect language from URL / Cookie / HeaderLocale Detection
Implement paths with locale prefixes, such as /en/aboutRouting Integration
Load translation resources from a remote service or platformResource Loading -> Custom Backend
SSR, multiple entries, or custom instancesAdvanced Usage
Look up Hooks / components / type definitionsAPI Reference

Core Capabilities

  • Locale detection: Supports detection from URL path, Cookie, LocalStorage, request headers, browser settings, and other sources, with configurable priority.
  • Resource loading: Supports HTTP static files, file system loading for SSR, custom SDK functions, and chained backend progressive loading.
  • Routing integration: Automatically adds locale path prefixes such as /en/about, and provides the I18nLink component for locale-aware navigation.
  • SSR support: Detects the language on the server and injects it into the page so the client can reuse it directly and avoid language flicker.
  • TypeScript support: Provides complete type definitions and supports type-safe translation keys.