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
从 Polyglot.js 迁移到 Intlayer
如果您正在使用 Airbnb 的 Polyglot.js,使用兼容层迁移到 Intlayer 非常简单直接。
操作步骤
只需在您的项目中运行初始化命令:
bash
复制代码
复制代码到剪贴板
npx intlayer init这将生成 intlayer.config.ts。然后,您可以使用 bundler 插件别名将 Polyglot 导入透明地重定向到 @intlayer/polyglot。
底层原理
Polyglot.js 语法通常依赖于 polyglot.t('key', {name}),使用 %{name} 插值和以 "singular |||| plural" 分隔的 smart_count 复数。
底层实现:
- 插值: 兼容层原生处理
%{var}占位符。 - 复数: 字符串在
||||处被分割,并根据活动语言环境针对原生Intl.PluralRules进行求值,按照 Polyglot 自身的每语言环境桶顺序进行处理。 - 字典: 您无需向
new Polyglot()提供大型 JSON 配置——Intlayer 动态处理字典并自动进行修剪。