Creation:2026-06-13Last update:2026-06-13
将此文档参考到您的 AI 助手ChatGPTClaudeDeepSeekGoogle AI modeGeminiPerplexityMistralGrok
使用您最喜欢的AI助手总结文档,并引用此页面和AI提供商
版本历史
- "Init history"v9.0.02026/6/13
此页面的内容已使用 AI 翻译。
查看英文原文的最新版本Edit this doc
If you have an idea for improving this documentation, please feel free to contribute by submitting a pull request on GitHub.
GitHub link to the documentationCopy
Copy doc Markdown to clipboard
从 next-i18next 迁移到 Intlayer
有关完整详细的分步教程,请参阅我们完整的 next-i18next 迁移指南。
Intlayer 透明地处理所有 Next.js Pages Router 和 App Router 实现。使用适配器可以让您以零代码重写的方式迁移 next-i18next 实现。
操作步骤
首先,运行:
bash
复制代码
复制代码到剪贴板
npx intlayer init这将创建所需的 Intlayer 设置文件。要在后台切换到 Intlayer,请更新您的 next.config.ts:
next.config.ts
复制代码
复制代码到剪贴板
import type { NextConfig } from "next";import { createNextI18nPlugin } from "@intlayer/next-i18next/plugin";const withIntlayer = createNextI18nPlugin();const nextConfig: NextConfig = {};export default withIntlayer(nextConfig);底层原理
createNextI18nPlugin 将 Next.js 的原生行为与核心 next-intlayer 插件组合在一起,为 next-i18next、react-i18next 和 i18next 注入所有必需的 Webpack/Turbopack 别名。
底层实现:
serverSideTranslations和appWithTranslation: 现在作为 Intlayer 内部加载器的包装器运行,绕过了大型静态 JSON 注入。- 客户端 hook: 立即委托给
@intlayer/react-i18next,保留所有格式化、复数和嵌套命名空间功能。