Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(avatarcropper): 多语言支持 #2666

Merged
merged 2 commits into from
Oct 30, 2024
Merged

Conversation

xiaoyatong
Copy link
Collaborator

@xiaoyatong xiaoyatong commented Oct 28, 2024

🤔 这个变动的性质是?

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

🔗 相关 Issue

💡 需求背景和解决方案

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

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

  • 文档已补充或无须补充
  • 代码演示已提供或无须提供
  • TypeScript 定义已补充或无须补充
  • fork仓库代码是否为最新避免文件冲突
  • Files changed 没有 package.json lock 等无关文件

Summary by CodeRabbit

  • 新功能

    • 增强了头像裁剪组件的国际化功能,动态使用用户语言设置的本地化字符串更新编辑文本和工具栏按钮标签。
  • 样式

    • 修改了头像裁剪组件的样式,增加了工具栏的内边距,并移除了裁剪项的内边距,以优化用户界面。

Copy link

coderabbitai bot commented Oct 28, 2024

Important

Review skipped

Review was skipped due to path filters

⛔ Files ignored due to path filters (1)
  • src/packages/avatarcropper/__tests__/__snapshots__/avatarcropper.spec.tsx.snap is excluded by !**/*.snap

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

此次更改涉及avatarcropper.scssavatarcropper.tsx文件。avatarcropper.scss文件的主要修改包括对.nut-avatar-cropper组件及其子元素的样式进行调整,添加了新的内边距属性,并删除了某些元素的内边距。avatarcropper.tsx文件的主要更改是更新AvatarCropper组件的defaultProps,使editText属性和工具栏按钮标签使用本地化字符串,以增强国际化能力。

Changes

文件路径 更改摘要
src/packages/avatarcropper/avatarcropper.scss 修改.nut-avatar-cropper-toolbar-flex类的内边距,删除.nut-avatar-cropper-item类的内边距,调整RTL布局属性。
src/packages/avatarcropper/avatarcropper.tsx 更新defaultProps中的editTexttoolbar属性,使用本地化字符串替代静态字符串。

Possibly related PRs

Suggested labels

size/L

Suggested reviewers

  • oasis-cloud

Poem

在草地上跳跃的小兔,
新样式让我们欢呼,
本地化的文本闪耀光芒,
头像裁剪更添一份美好。
让我们一起欢庆这变化,
兔子们齐声歌唱,真是妙! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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 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.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (4)
src/packages/avatarcropper/avatarcropper.scss (1)

69-69: 工具栏内边距调整看起来合理

内边距的添加改善了工具栏按钮的布局间距。不过建议考虑在不同屏幕尺寸下使用响应式的内边距值,以获得更好的适配效果。

可以考虑使用以下方式优化响应式布局:

- padding: 15px 15px;
+ padding: clamp(10px, 3vw, 15px);
src/packages/avatarcropper/avatarcropper.tsx (3)

64-64: 建议添加类型安全检查

为了确保国际化文本的类型安全,建议在使用 locale.edit 之前添加空值检查。这样可以防止在某些语言配置缺失时出现运行时错误。

建议修改为:

- defaultProps.editText = locale.edit
+ defaultProps.editText = locale.edit || defaultProps.editText

Line range hint 47-57: 建议统一国际化键值的访问方式

目前的实现中,国际化键值的访问方式不统一:

  • locale.cancellocale.confirm 直接从根对象访问
  • locale.avatarCropper.rotate 使用嵌套对象访问
  • locale.reset 直接从根对象访问

建议将所有与头像裁剪相关的文本都移到 avatarCropper 命名空间下,以保持一致性。

建议修改为:

  defaultProps.toolbar = [
    <Button type="danger" key="cancel">
-     {locale.cancel}
+     {locale.avatarCropper.cancel}
    </Button>,
    <Button key="reset">
-     {locale.reset}
+     {locale.avatarCropper.reset}
    </Button>,
    <Button key="rotate">{locale.avatarCropper.rotate}</Button>,
    <Button type="success" key="confirm">
-     {locale.confirm}
+     {locale.avatarCropper.confirm}
    </Button>,
  ]

Line range hint 467-473: 建议增强无障碍访问支持

虽然已经添加了 aria-label 属性,但还可以进一步改善组件的无障碍访问支持:

  1. 为交互元素添加适当的角色(role)属性
  2. 为工具栏按钮添加 aria-label 属性
  3. 为裁剪区域添加适当的 ARIA 属性以提供更好的屏幕阅读器支持

建议添加以下改进:

  <div
    className={`${classPrefix}-popup-highlight`}
+   role="region"
+   aria-label={locale.avatarCropper.cropRegion}
    onTouchStart={onTouchStart}
    onTouchMove={onTouchMove}
    onTouchEnd={onTouchEnd}
  >
    <div className="highlight" style={highlightStyle} />
  </div>

以及为工具栏按钮添加 aria-label:

  <Button type="danger" key="cancel">
+   aria-label={locale.avatarCropper.cancelLabel}
    {locale.avatarCropper.cancel}
  </Button>
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 2f71fda and de88f57.

📒 Files selected for processing (2)
  • src/packages/avatarcropper/avatarcropper.scss (1 hunks)
  • src/packages/avatarcropper/avatarcropper.tsx (1 hunks)

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (2)
src/packages/avatarcropper/avatarcropper.scss (1)

69-69: 建议使用 CSS 变量来定义内边距值

工具栏的内边距值目前是硬编码的。建议将其改为使用 CSS 变量,以便于维护和主题定制。

建议按照以下方式修改:

-        padding: 15px 15px;
+        padding: var(--nut-avatar-cropper-toolbar-padding, 15px 15px);
src/packages/avatarcropper/avatarcropper.tsx (1)

Line range hint 41-64: 建议添加默认的英文回退文本

为了提高代码的健壮性,建议在使用 locale 对象时添加默认的英文回退文本,以防 locale 对象未正确加载或某些翻译缺失的情况。

建议按照以下方式修改:

  defaultProps.toolbar = [
    <Button type="danger" key="cancel">
-     {locale.cancel}
+     {locale.cancel || 'Cancel'}
    </Button>,
-   <Button key="reset">{locale.reset}</Button>,
+   <Button key="reset">{locale.reset || 'Reset'}</Button>,
    <Button key="rotate">
-     {locale.avatarCropper.rotate}
+     {locale.avatarCropper?.rotate || 'Rotate'}
    </Button>,
    <Button type="success" key="confirm">
-     {locale.confirm}
+     {locale.confirm || 'Confirm'}
    </Button>,
  ]
- defaultProps.editText = locale.edit
+ defaultProps.editText = locale.edit || 'Edit'
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 2f71fda and de88f57.

📒 Files selected for processing (2)
  • src/packages/avatarcropper/avatarcropper.scss (1 hunks)
  • src/packages/avatarcropper/avatarcropper.tsx (1 hunks)
🔇 Additional comments (4)
src/packages/avatarcropper/avatarcropper.scss (1)

Line range hint 126-160: RTL 支持实现完善

组件的 RTL(从右到左)布局支持实现得很完整,包括了所有必要的位置调整和变换。这对于支持阿拉伯语等 RTL 语言的用户体验很重要。

src/packages/avatarcropper/avatarcropper.tsx (3)

Line range hint 41-63: 工具栏按钮已正确实现国际化支持

工具栏按钮的文本已经正确地使用了 locale 对象中的对应翻译文本,包括取消、重置、旋转和确认按钮。实现方式符合国际化最佳实践。


64-64: 编辑文本已正确实现国际化支持

编辑文本已经正确地使用了 locale.edit 进行国际化支持。


Line range hint 41-64: 验证国际化文本的完整性

让我们验证一下是否所有需要的翻译键都在 locale 对象中定义了。

✅ Verification successful

国际化文本验证完成,所有必需的翻译键均已定义

经过验证,AvatarCropper 组件使用的所有国际化文本键(cancel、reset、rotate、confirm、edit、selectImage)在所有语言包中都已正确定义,包括:

  • 基础键:cancel、confirm、edit、reset
  • avatarCropper 对象下的键:rotate、selectImage

所有翻译内容完整且符合规范。

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 描述:检查 locale 文件中是否包含所有必需的翻译键

# 搜索 locale 定义文件
echo "正在搜索 locale 定义文件..."
rg -l "export.*default.*{" --type ts

# 搜索使用的翻译键
echo "正在搜索组件中使用的翻译键..."
rg "locale\." --type tsx

Length of output: 429


Script:

#!/bin/bash
# 搜索 locale 定义文件
echo "搜索 locale 定义文件..."
rg -l "export.*default.*\{" -g "*.ts"

# 搜索使用的翻译键
echo "搜索组件中使用的翻译键..."
rg "locale\." -g "*.tsx" -A 1 src/packages/avatarcropper/

Length of output: 2416


Script:

#!/bin/bash
# 搜索 locale 相关的定义文件
echo "搜索语言包定义..."
rg -l "locale.*avatarCropper" -g "*.ts" src/

# 检查语言包中的键值定义
echo "检查语言包中的键值..."
rg "avatarCropper|cancel|confirm|reset|edit" -g "*.ts" src/locales/

Length of output: 2353

Copy link

codecov bot commented Oct 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.07%. Comparing base (2f71fda) to head (0c4ecf8).
Report is 4 commits behind head on next.

Additional details and impacted files
@@           Coverage Diff           @@
##             next    #2666   +/-   ##
=======================================
  Coverage   84.07%   84.07%           
=======================================
  Files         217      217           
  Lines       17829    17830    +1     
  Branches     2608     2608           
=======================================
+ Hits        14990    14991    +1     
  Misses       2834     2834           
  Partials        5        5           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@xiaoyatong xiaoyatong requested a review from irisSong October 30, 2024 01:46
@irisSong irisSong merged commit 40099b0 into jdf2e:next Oct 30, 2024
5 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Nov 8, 2024
20 tasks
@coderabbitai coderabbitai bot mentioned this pull request Dec 30, 2024
20 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants