Skip to content

使用 Translator 格式化下载速度#4709

Merged
Glavo merged 6 commits intoHMCL-dev:mainfrom
Glavo:translate-others
Oct 22, 2025
Merged

使用 Translator 格式化下载速度#4709
Glavo merged 6 commits intoHMCL-dev:mainfrom
Glavo:translate-others

Conversation

@Glavo
Copy link
Copy Markdown
Member

@Glavo Glavo commented Oct 21, 2025

No description provided.

Copilot AI review requested due to automatic review settings October 21, 2025 07:49
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the download speed formatting logic by moving it from inline code into a centralized Translator utility. The purpose is to enable locale-specific formatting of speed values and improve code maintainability by eliminating duplication.

Key changes:

  • Added a new formatSpeed(long bytes) method to the Translator class and I18n utility
  • Refactored TaskExecutorDialogPane to use the new centralized formatting method instead of inline speed calculation
  • Extended Translator_en_Qabs to apply translation to formatted speed strings

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
Translator.java Implements core speed formatting logic with KiB/s and MiB/s unit conversions
I18n.java Adds public API method to delegate speed formatting to the translator
Translator_en_Qabs.java Overrides formatSpeed to apply translation to the formatted output
TaskExecutorDialogPane.java Replaces inline speed formatting code with call to I18n.formatSpeed

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

import org.jackhuang.hmcl.download.RemoteVersion;
import org.jackhuang.hmcl.util.i18n.SupportedLocale;

import java.text.DecimalFormat;
Copy link

Copilot AI Oct 21, 2025

Choose a reason for hiding this comment

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

The DecimalFormat import is unused. This import should be removed as the code uses String.format() instead.

Suggested change
import java.text.DecimalFormat;

Copilot uses AI. Check for mistakes.
speed /= 1024;
unit = "KiB/s";
}
if (speed > 1024) {
Copy link

Copilot AI Oct 21, 2025

Choose a reason for hiding this comment

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

The second condition should check if speed >= 1024 instead of speed > 1024 to ensure consistent unit boundaries. A speed of exactly 1024 KiB/s should be displayed as 1.0 MiB/s, not 1024.0 KiB/s.

Suggested change
if (speed > 1024) {
if (speed >= 1024) {

Copilot uses AI. Check for mistakes.
@3gf8jv4dv
Copy link
Copy Markdown
Contributor

3gf8jv4dv commented Oct 21, 2025

这个 PR 里涉及的文本能否实现 i18n?一些斯拉夫语言(如俄语、乌克兰语)是用西里尔字母表示这些单位的。

@Glavo
Copy link
Copy Markdown
Member Author

Glavo commented Oct 21, 2025

这个 PR 里涉及的文本能否实现 i18n?一些斯拉夫语言(如俄语、乌克兰语)是用西里尔字母表示这些单位的。

可以,使用 Translator 的目的就是方便实现格式化。

你可以把对应的文本给我,我实现一下这些语言的本地化。

@3gf8jv4dv

This comment was marked as resolved.

@Glavo Glavo requested a review from Copilot October 22, 2025 12:33
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@HMCL-dev HMCL-dev deleted a comment from Copilot AI Oct 22, 2025
@Glavo Glavo merged commit f2032ab into HMCL-dev:main Oct 22, 2025
2 checks passed
@Glavo Glavo deleted the translate-others branch October 22, 2025 12:35
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.

3 participants