Internationalization
@modern-js/plugin-i18n 是 Modern.js 的国际化插件,基于 i18next 和 react-i18next 构建。
- 插件本身:负责与 Modern.js 框架的集成,如 SSR 语言传递、路由前缀处理等
- i18next:核心翻译能力,如
t()函数、插值、复数、命名空间。 - react-i18next:React 组件和 Hook,如
useTranslation,实现与 React 生命周期的结合。
Where to start?
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 theI18nLinkcomponent 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.