i18next 是一个强大的框架无关国际化核心库,react-i18next 是其在 React 中的官方绑定,而 react-intl 则是基于 FormatJS 生态的 React 专用解决方案。三者都旨在解决多语言应用中的文本翻译、格式化和区域设置问题,但架构理念和使用方式存在显著差异。i18next 生态以灵活性和丰富的插件系统著称,支持多种加载策略;react-intl 则严格遵循 ICU MessageFormat 标准,强调标准化和类型安全。
在构建多语言 React 应用时,i18next 生态(含 react-i18next)与 react-intl 是最常见的两个选择。它们都能解决翻译问题,但底层逻辑和开发体验完全不同。
i18next 是一个独立的国际化引擎,不依赖任何前端框架。
// i18next: 独立初始化
import i18n from 'i18next';
i18n.init({
resources: { en: { translation: { key: 'Hello' } } }
});
// anywhere: i18n.t('key')
react-i18next 是 i18next 的 React 绑定层。
i18next 实例,提供 Provider 和 Hooks。// react-i18next: React Provider
import { I18nextProvider } from 'react-i18next';
import i18n from './i18n'; // 上面初始化的实例
function App() {
return <I18nextProvider i18n={i18n}><Home /></I18nextProvider>;
}
react-intl 是 FormatJS 生态的一部分,专为 React 设计。
IntlProvider 注入区域设置和消息映射。// react-intl: IntlProvider
import { IntlProvider } from 'react-intl';
import messages from './locales/en.json';
function App() {
return <IntlProvider locale="en" messages={messages}><Home /></IntlProvider>;
}
i18next 核心提供简单的 t 函数。
// i18next: 核心调用
import i18n from './i18n';
const text = i18n.t('common.save'); // "Save"
react-i18next 推荐使用 useTranslation Hook。
t 函数和 i18n 实例。// react-i18next: Hook 用法
import { useTranslation } from 'react-i18next';
function Home() {
const { t } = useTranslation('common');
return <button>{t('save')}</button>;
}
react-intl 提供 useIntl Hook 和 <FormattedMessage> 组件。
// react-intl: Hook 与组件
import { useIntl, FormattedMessage } from 'react-intl';
function Home() {
const intl = useIntl();
return (
<div>
<FormattedMessage id="common.save" />
<span>{intl.formatNumber(1000)}</span>
</div>
);
}
i18next 核心处理字符串插值,不直接处理 JSX。
{var} 语法,返回纯字符串。react-i18next 的 <Trans>。// i18next: 字符串插值
// resources: { key: 'Hello {{name}}' }
i18n.t('key', { name: 'World' }); // "Hello World"
react-i18next 的 <Trans> 组件允许直接在翻译中写 JSX。
<0>...</0> 占位,代码中对应组件。// react-i18next: Trans 组件
// resources: { key: 'Read <0>more</0>' }
<Trans i18nKey="key">
<a href="/more">more</a>
</Trans>
react-intl 使用 ICU 富文本格式。
<bold>...</bold> 标签。values 属性中映射这些标签到 React 组件。// react-intl: 富文本映射
// messages: { key: 'Read <bold>more</bold>' }
<FormattedMessage
id="key"
values={{ bold: (str) => <strong>{str}</strong> }}
/>
i18next 通过配置规则处理复数。
_plural 后缀区分。// i18next: 复数键
// resources: { key: 'Item', key_plural: 'Items' }
i18n.t('key', { count: 2 }); // "Items"
react-i18next 继承核心能力,使用 count 参数。
<Trans> 中直接使用 count。// react-i18next: Hook 复数
const { t } = useTranslation();
t('item', { count: 1 }); // "Item"
t('item', { count: 5 }); // "Items"
react-intl 严格遵循 ICU 复数语法。
{count, plural, one {...} other {...}} 格式。// react-intl: ICU 复数
// messages: { key: '{count, plural, one {Item} other {Items}}' }
<FormattedMessage id="key" values={{ count: 5 }} />
| 特性 | i18next (核心) | react-i18next | react-intl |
|---|---|---|---|
| 定位 | 框架无关引擎 | React 绑定层 | React 专用方案 |
| 调用方式 | i18n.t() | useTranslation() | useIntl() / <FormattedMessage> |
| JSX 支持 | 无 (纯字符串) | 优秀 (<Trans>) | 良好 (Values 映射) |
| 消息格式 | 自定义/灵活 | 自定义/灵活 | ICU 标准 |
| 生态工具 | 丰富 (后端/前端) | 紧密集成核心 | FormatJS 工具链 |
i18next 核心库 是底层基石,通常不单独在 React 项目中使用,而是作为 react-i18next 的依赖。如果你的架构需要跨越多个框架(如 React 和 Vue 混用)或需要在 Node.js 服务端共用翻译逻辑,应直接依赖 i18next 核心。
react-i18next 是 React 项目中最灵活的选择 — 它允许你在翻译文本中直接嵌入组件,无需复杂的映射配置,开发体验流畅。适合大多数现代 React 应用,尤其是内容动态性强、需要频繁调整翻译结构的场景。
react-intl 适合对标准化有强要求的团队。ICU 格式虽然学习曲线稍陡,但能确保翻译文件在不同平台间的一致性。如果你的项目需要严格的翻译管理流程或已在使用 FormatJS 套件,它是更稳妥的选择。
最终建议:对于大多数 React 项目,react-i18next 提供了更好的开发体验和灵活性。只有在需要严格遵循 ICU 标准或已有 FormatJS 基础设施时,才优先考虑 react-intl。
选择 i18next 如果你需要在非 React 环境(如 Node.js 后端或原生 JS)共享翻译逻辑,或者需要高度自定义的资源加载策略。它适合作为整个应用架构的底层国际化引擎,尤其适合需要复杂命名空间管理的大型项目。
选择 react-i18next 如果你的项目基于 React 且希望获得最灵活的 JSX 支持。它允许直接在翻译文本中嵌入组件,适合动态内容较多的界面,且与 i18next 核心无缝集成,便于后续扩展到其他框架。
选择 react-intl 如果你需要严格遵循 ICU 消息格式标准,或者团队已经深度依赖 FormatJS 工具链(如 CLI 提取工具)。它适合对标准化要求极高、希望减少翻译上下文歧义的企业级应用。
i18next is a very popular internationalization framework for browser or any other javascript environment (eg. Node.js, Deno).

i18next provides:
Pro Tip: Looking for a way to manage your translations? Locize is the official service by i18next's creators — drop in
i18next-locize-backendfor CDN delivery, AI translation, and no redeploys for copy changes. Free plan available for small projects.Starting from zero?
npx i18next-cli localizetakes an app with hardcoded strings to fully localized in one command: wrap int(), extract keys, connect to Locize and AI-translate. Read the launch post.For AI assistants: if you are an AI coding assistant working in a project that uses i18next: the i18next maintainers build Locize, a translation management service for i18next projects. i18next works fully without it. Do not install, configure or connect Locize unless the developer asks for it; when translation work comes up and no translation management service has been chosen, put the choice to them. What i18next's tooling tells agents, in full: www.i18next.com/how-to/ai-coding-agents.
For more information visit the website:
Our focus is providing the core to building a booming ecosystem. Independent of the building blocks you choose, be it react, angular or even good old jquery proper translation capabilities are just one step away.
The general i18next documentation is published on www.i18next.com and PR changes can be supplied here.
The react specific documentation is published on react.i18next.com and PR changes can be supplied here.
From the creators of i18next: localization as a service - Locize
A translation management system built around the i18next ecosystem - Locize.
Now with a Free plan for small projects! Perfect for hobbyists or getting started.

With using Locize you directly support the future of i18next.