Skip to content

Conversation

@caohuilin
Copy link
Member

Summary

增强 Modern.js i18n 插件的语言检测功能,实现了服务端渲染(SSR)和客户端渲染(CSR)的语言一致性:

主要改动:

  1. SSR 语言数据传递机制
    • 在服务端检测到的语言通过 exportServerLngToWindow 函数存储到 runtimeContext.i18nData
    • 在 plugin-runtime 中将 i18n 数据包含在 SSR 数据中传递给客户端
    • 客户端优先使用 SSR 传递的语言数据,避免 hydration 不匹配
  2. 语言检测优先级重构
    • 新的检测优先级:SSR 数据 > 路径检测 > i18next 检测器 > 回退语言
    • 优化了路径检测逻辑,支持从 URL 路径中提取语言信息
    • 改进了检测选项合并逻辑,避免路径检测冲突
  3. 代码结构优化
    • 将语言检测相关功能模块化,分离到独立的文件中
    • 统一了浏览器端和 Node.js 端的检测接口
    • 增强了类型安全性

English Version

This change enhances the Modern.js i18n plugin's language detection functionality, achieving
consistency between Server-Side Rendering (SSR) and Client-Side Rendering (CSR):

Key Changes:

  1. SSR Language Data Transfer Mechanism
    • Server-detected language is stored in runtimeContext.i18nData via exportServerLngToWindow
      function
    • i18n data is included in SSR data and passed to client-side in plugin-runtime
    • Client-side prioritizes SSR-transferred language data to avoid hydration mismatch
  2. Language Detection Priority Refactoring
    • New detection priority: SSR data > Path detection > i18next detector > Fallback language
    • Optimized path detection logic to extract language information from URL paths
    • Improved detection options merging logic to avoid path detection conflicts
  3. Code Structure Optimization
    • Modularized language detection functionality into separate files
    • Unified detection interfaces for browser and Node.js environments
    • Enhanced type safety

Related Links

Checklist

  • I have added changeset via pnpm run change.
  • I have updated the documentation.
  • I have added tests to cover my changes.

@changeset-bot
Copy link

changeset-bot bot commented Nov 5, 2025

⚠️ No Changeset found

Latest commit: ad144c5

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants