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-intl 迁移到 Intlayer
有关完整详细的分步教程,请参阅我们完整的 next-intl 迁移指南。
从 next-intl 迁移到 Intlayer,让您的应用程序路由和语法完全不受干扰。
操作步骤
在您的仓库中执行以下命令:
bash
复制代码
复制代码到剪贴板
npx intlayer init这将创建一个 intlayer.config.ts。在您的 next.config.ts 中,使用插件包装器无缝地将 next-intl 别名注入到 @intlayer/next-intl。
next.config.ts
复制代码
复制代码到剪贴板
import type { NextConfig } from "next";import { createNextIntlPlugin } from "@intlayer/next-intl/plugin";const withIntlayer = createNextIntlPlugin();const nextConfig: NextConfig = {};export default withIntlayer(nextConfig);底层原理
bundler 包装器替换了翻译,但保留 next-intl/navigation 功能完好无损(例如 Link、redirect、usePathname)。
底层实现:
- ICU 运行时: 复数(
=0、one、other)、select/selectordinal、#参数和格式化参数({ts, date, long})通过共享的resolveMessage(..., 'icu')解析器正确运行。 useTranslations()和getTranslations(): 裸作用域调用将第一个键段提取为正确的字典标识符。嵌套命名空间优雅地拆分为字典路径和前缀。- 富文本格式化:
t.rich()和t.markup()都经过完整的原生实现,将类 HTML 节点转换为渲染的 React chunk。 useFormatter:relativeTime、list、dateTimeRange和配置中的命名格式桥接到核心原生Intl格式化器。