接收有关即将发布的Intlayer的通知
    Creation:2025-09-22Last update:2025-09-22

    新版 Intlayer v6 - 新特性介绍

    欢迎使用 Intlayer v6!本次发布重点提升了性能、开发者体验和可靠性。以下是主要亮点,包括迁移说明和可复制粘贴的示例。

    亮点

    • 新命令:npx intlayer content test 用于检测缺失的翻译
    • 新增全局 autoFill 选项,用于自动生成缺失的翻译
    • 填充命令默认跳过已有翻译:npx intlayer fill
    • VS Code 扩展:新增 Intlayer 活动栏(搜索和词典)、工具栏/上下文操作、自动显示、填充/测试命令
    • 通过 Promise 并行化实现构建速度提升 10 倍
    • 远程词典缓存,避免应用启动时重复获取
    • 改进日志记录:设置 log.mode: 'verbose' 以检查行为
    • 更严格的验证,防止词典问题导致应用崩溃
    • 使用 build.importMode = 'live'pnpm intlayer live 实现与 CMS 的实时更新
    • 修复:Vue.js 集成、Lynx 适配器、Windows 上的可视化编辑器

    新功能:测试缺失的翻译

    快速审核项目,找出缺失的键/语言。

    bash
    npx intlayer content test

    输出:

    bash
    pnpm intlayer content test缺失的翻译: - blog-data       - 日语 (ja)、韩语 (ko)、中文 (zh)、德语 (de)、意大利语 (it) - src/components/BlogPage/blogData.content.ts - demo-page       - 法语 (fr)、意大利语 (it)                                         - src/components/DemoPage/demo.content.ts - locale-switcher - 意大利语 (it)、葡萄牙语 (pt)                                       - src/components/LocaleSwitcher/localeSwitcher.content.ts语言环境:英语 (en)、俄语 (ru)、日语 (ja)、法语 (fr)、韩语 (ko)、中文 (zh)、西班牙语 (es)、德语 (de)、阿拉伯语 (ar)、意大利语 (it)、英式英语 (en-GB)、葡萄牙语 (pt)、印地语 (hi)必需语言环境:英语 (en)缺少的语言环境:日语 (ja)、韩语 (ko)、中文 (zh)、德语 (de)、意大利语 (it)、法语 (fr)、葡萄牙语 (pt)缺少的必需语言环境:-缺少的语言环境总数:7缺少的必需语言环境总数:0

    查看更多 CLI 选项请参阅文档:CLI 参考 → “测试缺失的翻译”。以及 测试 指南。


    新功能:全局 autoFill 自动补全缺失翻译

    现在您可以全局启用 autoFill,任何缺失翻译的字典都会自动补全。

    intlayer.config.ts
    import { type IntlayerConfig, Locales } from "intlayer";const config: IntlayerConfig = {  internationalization: {    locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH],    defaultLocale: Locales.ENGLISH,    requiredLocales: [Locales.ENGLISH, Locales.FRENCH],  },  content: {    // 为所有词典自动生成缺失的翻译    autoFill: "./{{fileName}}.content.ts",    //    // autoFill: "/messages/{{locale}}/{{key}}/{{fileName}}.content.json",    //    // autoFill: true, // 自动为所有词典生成缺失的翻译,类似使用 "./{{fileName}}.content.json"    //    // autoFill: {    //   en: "./{{fileName}}.en.content.json",    //   fr: "./{{fileName}}.fr.content.json",    //   es: "./{{fileName}}.es.content.json",    // },  },};export default config;

    您仍然可以使用内容文件中的 autoFill 字段对每个字典进行微调。完整参考请见 doc/autoFilldoc/dictionary/content_file


    填充命令:更安全的默认设置

    填充命令现在默认只填充缺失的翻译,跳过已有内容。

    bash
    npx intlayer fill
    bash
    受影响的字典键处理:access-key-creation-form-schema, doc-search-metadata, doc-search-page  - [access-key-creation-form-schema]      字典没有文件路径。跳过。  - [access-key-creation-form-schema]      正在处理内容声明:src/components/Dashboard/ProjectForm/AccessKey/useAccessKeyCreationFormSchema.content.ts  - [access-key-creation-form-schema]      无需填充的语言 - 跳过字典  - [doc-search-metadata]                  字典没有文件路径。跳过。  - [doc-search-metadata]                  正在处理内容声明:src/app/[locale]/(docs)/doc/search/metadata.content.ts  - [doc-search-metadata]                  无需填充的语言环境 - 跳过字典  - [doc-search-page]                      字典没有文件路径。跳过。  - [doc-search-page]                      正在处理内容声明:src/app/[locale]/(docs)/doc/search/page.content.ts  - [doc-search-page]                     [俄语 (ru)]                   正在准备将字典从英语 (en) 翻译为俄语 (ru)[intlayer]  已对 src/app/[locale]/(docs)/doc/search/page.content.ts 应用 Prettier 格式化  - [doc-search-page]                      内容声明已写入 src/app/[locale]/(docs)/doc/search/page.content.ts

    CI 示例可在 CI/CD 中查看。


    更新的 VS Code 扩展

    该扩展现在在活动栏中包含了一个专用的 Intlayer 选项卡,并带来了多个工作流改进:

    • Intlayer 活动栏包含两个视图:
      • 搜索网页视图 (intlayer.searchBar),用于实时字典/内容搜索
      • 字典树 (intlayer.dictionaries),列出环境、字典和贡献文件
    • 字典视图上的工具栏:构建、拉取、推送、填充、刷新、测试、创建字典文件
    • 上下文菜单:字典上的拉取/推送;文件上的填充
    • 自动显示:在适用时,当前编辑器文件会在词典树中高亮显示
    • 命令面板新增命令:填充词典和测试词典

    详情请参见官方 VS Code 扩展文档。


    性能提升:快 10 倍

    • 本地和远程词典并行解析
    • 远程词典缓存,避免应用启动时重复获取
    bash
    npx intlayer build

    输出:

    bash
    [intlayer]  准备 Intlayer (v6.0.1)[intlayer]  词典:[intlayer]  ✓ 本地内容:163/163[intlayer]  ✓ 远程内容:100/100[intlayer]   - access-key-creation-form             [local: ✔ built] [distant: ✔ imported][intlayer]   - access-key-creation-form-schema      [本地: ✔ 构建完成] [远程: ✔ 导入完成][intlayer]   - access-key-form                      [本地: ✔ 构建完成] [远程: ✔ 导入完成][intlayer]   - ai-ab-testing-section                                 [远程: ✔ 导入完成][intlayer]   - application-not-running-view         [本地: ✔ 构建完成] [远程: ✔ 导入完成][intlayer]   - application-template-message         [本地: ✔ 构建完成] [远程: ✔ 获取完成][intlayer]   - aside-navigation                     [本地: ✔ 构建完成] [远程: ✔ 导入完成][intlayer]   - ask-reset-password                   [本地: ✔ 构建完成] [远程: ✔ 导入完成][intlayer]   - ask-reset-password-schema            [本地: ✔ 构建完成] [远程: ✔ 导入完成][intlayer]   - 自动完成部分               [本地: ✔ 构建完成] [远程: ✔ 获取完成][intlayer]   - 可用技术部分               [本地: ✔ 构建完成] [远程: ✔ 导入完成][intlayer]   - 博客数据                  [本地: ✔ 构建完成][intlayer]   - 博客元数据                [本地: ✔ 构建完成][intlayer]   - 博客导航列表              [本地: ✔ 构建完成] [远程: ✔ 导入完成][intlayer]   - 博客页面                  [远程: ✔ 获取完成][intlayer]   - 博客搜索元数据            [本地: ✔ 构建完成] [远程: ✔ 导入完成][intlayer]   - 博客搜索页面              [本地: ✔ 构建完成] [远程: ✔ 导入完成]...[intlayer]  内容已加载  (总计: 8401毫秒 - 本地: 4050毫秒 - 远程: 4222毫秒)

    日志改进

    日志系统已得到改进,能够提供有关构建和运行时转换过程中发生情况的更详细信息。

    启用详细日志以更好地了解构建和运行时转换过程中发生的情况。

    intlayer.config.ts
    export default {  log: {    mode: "verbose", // 选项: "default" | "verbose" | "disabled"  },};

    有关所有日志选项,请参见配置


    更强的验证

    字典处理现在执行更强健的验证。当字典处理失败时,Intlayer 会避免破坏您的应用程序,并显示可操作的错误信息。


    使用 CMS 的实时更新(生产安全)

    在生产环境中提供实时内容更新(例如,编辑更新),无需重新构建您的应用程序。

    1. 启用实时导入模式:
    intlayer.config.ts
    import { type IntlayerConfig } from "intlayer";const config: IntlayerConfig = {  build: {    importMode: "live", // "static" | "dynamic" | "live"  },  editor: {    liveSync: true, // 启用服务器端实时同步  },};export default config;
    1. 运行您的应用程序并实时处理并行执行:
    bash
    npx intlayer live --process 'vite preview'

    注意:

    • 只有标记为使用实时模式的字典会被实时获取。其他字典则经过性能优化。
    • 如果无法访问实时 API,则回退到动态导入。

    请参阅CMS 和实时同步配置以获取完整指南。


    迁移说明

    • 移除:dictionaryOutput(之前为 i18nextnext-intl)。此功能将在未来版本中以可插拔适配器形式回归。请从配置中删除该字段。
    • 相关移除:i18nextResourcesDir(详见 doc/configuration 更新日志)。
    • 推荐使用新的全局选项 content.autoFill 来大规模生成缺失的翻译。
    • 使用 npx intlayer content test 来检测 PR 中缺失的翻译。
    • 若需详细诊断,请设置 log.mode = 'verbose'

    修复

    • Vue.js 集成稳定性提升
    • Lynx 适配器改进
    • Windows 上的可视化编辑器

    有用的链接

    接收有关即将发布的Intlayer的通知