Skip to content

fix: 🐛 修复部分国际化文本不正确的问题#970

Merged
Moonofweisheng merged 1 commit into
masterfrom
fix/locale-text-error
Mar 24, 2025
Merged

fix: 🐛 修复部分国际化文本不正确的问题#970
Moonofweisheng merged 1 commit into
masterfrom
fix/locale-text-error

Conversation

@Moonofweisheng

@Moonofweisheng Moonofweisheng commented Mar 24, 2025

Copy link
Copy Markdown
Owner

🤔 这个 PR 的性质是?(至少选择一个)

  • 日常 bug 修复
  • 新特性提交
  • 站点、文档改进
  • 演示代码改进
  • 组件样式/交互改进
  • TypeScript 定义更新
  • CI/CD 改进
  • 包体积优化
  • 性能优化
  • 功能增强
  • 国际化改进
  • 代码重构
  • 代码风格优化
  • 测试用例
  • 分支合并
  • 其他改动(是关于什么的改动?)

🔗 相关 Issue

💡 需求背景和解决方案

修复部分国际化文本不正确的问题

☑️ 请求合并前的自查清单

⚠️ 请自检并全部勾选全部选项⚠️

  • 文档已补充或无须补充
  • 代码演示已提供或无须提供
  • TypeScript 定义已补充或无须补充

Summary by CodeRabbit

  • 新增功能
    • 改进了翻译逻辑,现支持动态处理消息,并在缺失翻译时提供更合理的回退文案。
  • 样式更新
    • 调整了分页组件的文案格式:英文版采用标准冒号显示,法文版移除了冒号前的多余空格,确保界面文案更加统一和专业。

@vercel

vercel Bot commented Mar 24, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
wot-design-uni ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 24, 2025 1:21pm

@coderabbitai

coderabbitai Bot commented Mar 24, 2025

Copy link
Copy Markdown

Walkthrough

该 PR 对翻译逻辑和分页文本格式进行了修改。在 useTranslate.ts 中,引入了 isDef 方法,并调整了 translate 函数的判断逻辑,以区分函数和非函数类型的 message,从而在 message 未定义时返回备用格式。在本地化文件中(en-US.tsfr-FR.ts),将分页组件中冒号的全角格式统一替换为半角格式,确保使用标准英文和法文标点。该 PR 未修改任何公开实体的声明。

Changes

文件路径 修改内容描述
src/uni_modules/.../composables/useTranslate.ts 添加 isDef 导入,更新 translate 函数逻辑:判断 message 类型并处理未定义情况。
src/uni_modules/.../locale/lang/en-US.ts
src/uni_modules/.../locale/lang/fr-FR.ts
修改分页组件文本格式:将全角冒号或空格冒号替换为半角冒号,符合标准标点规范。

Sequence Diagram(s)

sequenceDiagram
    participant Caller as 调用者
    participant Translate as translate()
    Note over Translate: 检查 message 类型及定义情况
    Caller->>Translate: 调用 translate(key, args)
    alt message 为函数
        Translate-->>Caller: 返回 message(args) 的结果
    else message 非函数
        Translate-->>Translate: 调用 isDef(message)
        alt message 定义
            Translate-->>Caller: 返回 message
        else 未定义
            Translate-->>Caller: 返回 `${prefix}${key}` 备选字符串
        end
    end
Loading

Possibly related PRs

Poem

小兔跳跃代码间,
翻译逻辑焕新颜。
冒号换半角,分页变得精简,
行云流水般执行顺畅。
代码森里春意满,🐰🍀 共庆更新欢!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 460a838 and 0234e9c.

📒 Files selected for processing (3)
  • src/uni_modules/wot-design-uni/components/composables/useTranslate.ts (1 hunks)
  • src/uni_modules/wot-design-uni/locale/lang/en-US.ts (1 hunks)
  • src/uni_modules/wot-design-uni/locale/lang/fr-FR.ts (1 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
src/uni_modules/wot-design-uni/components/composables/useTranslate.ts (1)
src/uni_modules/wot-design-uni/components/common/util.ts (4)
  • camelCase (293-295)
  • getPropByPath (664-672)
  • isFunction (317-319)
  • isDef (80-80)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (4)
src/uni_modules/wot-design-uni/locale/lang/fr-FR.ts (1)

78-79:

❓ Verification inconclusive

更改法语分页文本中的冒号格式

将法语分页文本中的"Page : ${value}"和"Total : ${total}"更改为"Page: ${value}"和"Total: ${total}",移除了冒号前的空格。这种改变使格式与英文版本保持一致,但请注意,在法语排版规则中,冒号前通常应保留空格。

您可能需要确认这是否符合项目的国际化标准,以及是否在所有语言中统一使用相同的标点格式。


🌐 Web query:

法语中冒号前是否应该有空格

💡 Result:

在法语中,冒号(:)前后均需添加空格,这一规则与英语用法有显著区别。具体规范如下:

基本规则

  1. 前方空格要求
    冒号前需使用不可分割空格(espace insécable),通过组合键 Shift + Control + 空格(Windows)或 Option + 空格(Mac)输入。这种空格可避免标点因换行出现在下一行首。

  2. 后方空格要求
    冒号后方需添加普通空格(例如:Texte : texte)。

实际应用示例

Elle a annoncé : « Je pars demain. »  
Les ingrédients nécessaires sont : farine, œufs et lait.

特殊情况与技术实现

  • 排版软件处理:若在Word中设置为法语输入法,冒号前后会自动添加正确空格[3][7];其他软件可能需手动调整。
  • 数学或编程场景:若冒号用于公式或代码(如x:y),则遵循对应领域的规范,不适用法语空格规则。

常见错误对比

  • 错误写法Texte:texte(无空格)或Texte :texte(后方缺少空格)。
  • 正确写法Texte : texte(前后均有空格,且前方为不可分割空格)。

这一规则同样适用于其他组合标点(如分号;、问号?、感叹号!)[1][4][6][8]。

Citations:


请确认法语分页文本冒号格式与项目国际化标准的一致性

当前提交修改将法语分页文本中的格式从原来的 "Page : ${value}""Total : ${total}"(冒号前有空格)更改为 "Page: ${value}""Total: ${total}"(去除了冒号前的空格),这样使其与英文版本一致。但根据法语排版规范,冒号前应使用不可分割空格(即应显示为 "Page : ${value}""Total : ${total}")。请核查项目国际化标准,确认是否需要对法语版本保留该空格。如果标准要求遵循法语传统,请将文本修改为符合规范的格式。

src/uni_modules/wot-design-uni/components/composables/useTranslate.ts (2)

1-1: 添加了 isDef 导入

已导入 isDef 函数以增强翻译处理功能。


9-9: 改进了翻译回退机制

优化了翻译函数的返回逻辑,现在对未定义的翻译键提供了更好的回退机制。该改动使用 isDef 函数检查 message 是否已定义,如果未定义则返回键名作为回退值。这有助于防止未定义的国际化文本导致显示问题。

src/uni_modules/wot-design-uni/locale/lang/en-US.ts (1)

82-83: 修正了英文分页文本中的冒号格式

将英文分页文本中的全角冒号(":")更改为半角冒号(":"),这符合英文排版规范,是一个很好的国际化文本修正。

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@netlify

netlify Bot commented Mar 24, 2025

Copy link
Copy Markdown

Deploy Preview for wot-design-uni ready!

Name Link
🔨 Latest commit 0234e9c
🔍 Latest deploy log https://app.netlify.com/sites/wot-design-uni/deploys/67e15c18d1ee7e00085d989c
😎 Deploy Preview https://deploy-preview-970--wot-design-uni.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@petercat-assistant

Copy link
Copy Markdown

Walkthrough

修复了部分国际化文本不正确的问题,主要涉及翻译功能的改进和国际化文本格式的调整。

Changes

文件 概要
src/uni_modules/wot-design-uni/components/composables/useTranslate.ts 更新了 useTranslate 函数,增加了对未定义消息的处理。
src/uni_modules/wot-design-uni/locale/lang/en-US.ts 修正了分页文本中的标点符号。
src/uni_modules/wot-design-uni/locale/lang/fr-FR.ts 修正了分页文本中的标点符号。

const currentMessages = Locale.messages()
const message = getPropByPath(currentMessages, prefix + key)
return isFunction(message) ? message(...args) : message
return isFunction(message) ? message(...args) : isDef(message) ? message : `${prefix}${key}`

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change in the useTranslate function introduces a fallback mechanism for undefined messages, which is a good improvement for handling missing translations. This ensures that the application does not break and provides a clear indication of missing keys.

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying wot-design-uni with  Cloudflare Pages  Cloudflare Pages

Latest commit: 0234e9c
Status: ✅  Deploy successful!
Preview URL: https://ac84a0db.wot-design-uni.pages.dev
Branch Preview URL: https://fix-locale-text-error.wot-design-uni.pages.dev

View logs

@Moonofweisheng
Moonofweisheng merged commit 4319fa9 into master Mar 24, 2025
@Moonofweisheng
Moonofweisheng deleted the fix/locale-text-error branch March 24, 2025 13:26
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.

1 participant