使用您最喜欢的AI助手总结文档,并引用此页面和AI提供商
此页面的内容已使用 AI 翻译。
查看英文原文的最新版本如果您有改善此文档的想法,请随时通过在GitHub上提交拉取请求来贡献。
文档的 GitHub 链接复制文档 Markdown 到剪贴板
New Intlayer v9 - What's new?
Welcome to Intlayer v9! This major release marks a huge milestone in simplifying the migration path to Intlayer with Compat Adapter Packages for major i18n libraries (react-i18next, next-intl, vue-i18n, etc.) and adds support for rich content structures: Collections, Variants, and Dynamic Records.
Table of contents
Compat Adapter Packages
Migrating to Intlayer from popular i18n libraries is now easier than ever. We have created five compat packages that expose the exact same public APIs as standard i18n libraries but delegate all translation work to Intlayer at runtime.
Expose Same Public API with Strict Typing
By replacing imports, you get all the benefits of Intlayer (including compile-time type safety against your actual dictionaries) with minimal code changes:
@intlayer/i18next@intlayer/react-i18next@intlayer/next-intl@intlayer/next-i18next@intlayer/vue-i18n
For example, simply change:
复制代码到剪贴板
to:
复制代码到剪贴板
Your keys will now be strictly typed against your Intlayer dictionaries, offering full dot-path auto-completion in your IDE!
Bundler Alias Plugins (Vite, Next.js, Turbopack)
To allow migrating without rewriting all your import statements manually, each compat adapter package includes a custom bundler plugin (Vite or Next.js) under the /plugin subpath.
These plugins automatically rewrite existing imports (e.g. react-i18next or next-intl) to their @intlayer/* equivalents at build time.
Next.js (Webpack / Turbopack) Example
Instead of withIntlayer, wrap your Next.js configuration with the compat plugin:
复制代码到剪贴板
Vite (React, Vue, Solid, Svelte) Example
复制代码到剪贴板
Mutualized Runtime Resolver
All compat adapters now route translation resolution through a single, highly optimized runtime parser: @intlayer/core/messageFormat.
- Interpolate Message: Resolves standard
{{var}}(whitespace & dot-paths), ICU formatted args ({v, number, percent}etc.), and bare{var}templates. - Message Node Resolver: Resolves nested nodes:
insert(),plural()(CLDR plural rules),enu()(enumeration),gender(), HTML tags, arrays, and callable function nodes. - Tokenized Tag Parser: Supports inline XML/HTML tags and numbered tags (e.g.,
<1>children</1>) to power rich-text rendering out of the box.
Feature Spec: Collections, Variants & Dynamic Records
Intlayer v9 expands beyond static key-value objects, allowing dictionaries to declare dynamic layout structures that are fully typed end-to-end.
1. Collections
Define a CMS-managed list of ordered items (e.g. FAQs, products, or blog lists):
复制代码到剪贴板
Usage:
复制代码到剪贴板
2. Variants
Deliver A/B tests, seasonal headers, feature flags, or custom landing pages:
复制代码到剪贴板
Usage:
复制代码到剪贴板
3. Dynamic Records
Define dictionaries whose entries are loaded dynamically at runtime via query IDs:
复制代码到剪贴板
Usage:
复制代码到剪贴板
Dynamic Loading & Bundle Size Optimizations
To keep bundles extremely small, Intlayer v9 supports dynamic lazy loading.
In your configuration, set importMode to 'dynamic' or 'fetch':
复制代码到剪贴板
At build time, @intlayer/swc and @intlayer/babel scan your files and replace useIntlayer / getIntlayer calls with tree-shakeable wrappers (useDictionary / useDictionaryDynamic). Only the content required for the selected collection item, variant, or locale is loaded, preventing your production bundle from containing unused translations.
Migration notes from v8
If you are upgrading from v8, note that the v9 does not include breaking changes. But here are the key changes:
- Locales & Dialects: If using external i18n dependencies, add their respective compat adapter plugins in your configuration or bundler setup to automatically rewrite imports.
- Custom Selectors: When calling
useIntlayer, the second parameter is now reserved for an option object containing{ locale, item, variant, id }. If you previously passed a locale string directly, you can still do so, but using the options object is recommended for advanced selections.