Skip to content

通过解析 IANA 语言子标签注册表增强本地化功能#4675

Merged
Glavo merged 37 commits intoHMCL-dev:mainfrom
Glavo:iana
Oct 21, 2025
Merged

通过解析 IANA 语言子标签注册表增强本地化功能#4675
Glavo merged 37 commits intoHMCL-dev:mainfrom
Glavo:iana

Conversation

@Glavo
Copy link
Copy Markdown
Member

@Glavo Glavo commented Oct 15, 2025

No description provided.

Copilot AI review requested due to automatic review settings October 15, 2025 09:03
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 implements parsing of the IANA Language Subtag Registry to obtain mappings from individual languages to macro languages. The main purpose is to generate CSV files containing language mappings and variant-to-script relationships for localization support.

  • Adds a new Gradle task ParseLanguageSubtagRegistry that parses IANA language subtag data
  • Generates two CSV files: sublanguages.csv for macro language mappings and variant_to_script.csv for variant-to-script mappings
  • Refactors LocaleUtils to load language mappings from CSV files instead of hardcoded data

Reviewed Changes

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

File Description
ParseLanguageSubtagRegistry.java New Gradle task for parsing IANA Language Subtag Registry and generating CSV mappings
variant_to_script.csv Generated CSV file mapping script types to language variants
sublanguages.csv Generated CSV file mapping macro languages to their sub-languages
LocaleUtils.java Refactored to load language data from CSV files and added variant-to-script lookup

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

@Glavo Glavo changed the title 通过解析 IANA Language Subtag Registry 获取个体语言至宏语言的映射 通过解析 IANA 语言子标签增强本地化功能 Oct 16, 2025
@Glavo Glavo requested a review from Copilot October 16, 2025 14:16
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 11 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.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@Glavo Glavo changed the title 通过解析 IANA 语言子标签增强本地化功能 通过解析 IANA 语言子标签注册表增强本地化功能 Oct 17, 2025
Glavo added 4 commits October 17, 2025 20:29
# Conflicts:
#	HMCLCore/src/main/java/org/jackhuang/hmcl/util/i18n/LocaleUtils.java
@Glavo Glavo requested a review from Copilot October 21, 2025 07:34
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 10 out of 12 changed files in this pull request and generated 3 comments.


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

Comment on lines +226 to +227
if (currentValue != null) {
currentValue = currentValue + " " + line;
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.

String concatenation in loop can be inefficient. Consider using StringBuilder, especially since this appears to be handling multi-line values that could span several iterations.

Copilot uses AI. Check for mistakes.
updateItems();
} else if (line.startsWith(" ")) {
if (currentValue != null) {
currentValue = currentValue + " " + line;
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.

Continuation lines starting with ' ' should be trimmed before concatenation. The current code concatenates the entire line including leading spaces, which will result in multiple spaces in the value. Change to currentValue = currentValue + ' ' + line.trim();

Suggested change
currentValue = currentValue + " " + line;
currentValue = currentValue + " " + line.trim();

Copilot uses AI. Check for mistakes.
/// Typically, it normalizes ISO 639 alpha-3 codes to ISO 639 alpha-2 codes.
public static @NotNull String normalizeLanguage(String language) {
return language.isEmpty()
? "en"
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 empty language defaulting to 'en' is embedded in multiple places (here and in getPreferredLanguage). Consider extracting this to a constant or single method to ensure consistency across the codebase.

Suggested change
? "en"
? DEFAULT_LANGUAGE_KEY

Copilot uses AI. Check for mistakes.
@Glavo Glavo merged commit d7c6a23 into HMCL-dev:main Oct 21, 2025
2 checks passed
@Glavo Glavo deleted the iana branch October 21, 2025 07:37
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