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
从 Transloco 迁移到 Intlayer
如果您的 Angular 应用程序当前使用 @jsverse/transloco,您可以使用我们的兼容适配器迁移到 Intlayer。这一过渡让您在利用 Intlayer 强大字典结构的同时,维持现有的模板语法。
操作步骤
只需在您的项目中运行初始化命令:
bash
复制代码
复制代码到剪贴板
npx intlayer init这将生成必要的 intlayer.config.ts 配置。然后,您将用 @intlayer/transloco 模块替换您的 Transloco 导入,或依赖构建别名。
底层原理
Transloco 使用作用域和 TranslocoService(translate、selectTranslate),以及结构性指令(*transloco="let t")和管道(| transloco)。
底层实现:
- 作用域: 自然映射到 Intlayer 字典键,为 bundle 优化提供出色的修剪能力。
- 服务和指令: Intlayer 的 Angular 适配器无缝替换了 provider,允许您现有的模板管道和指令针对 Intlayer 字典解析字符串。
- 构建时解析: TypeScript 分析器识别
instant/get调用,即使模板使用无法静态跟踪,回退修剪也能确保正确性。