Skip to content

Update HelpPage.java #3268

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

Closed
wants to merge 3 commits into from
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions HMCL/src/main/java/org/jackhuang/hmcl/ui/main/HelpPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

import java.util.Collections;
import java.util.List;
import java.util.Locale;

import static org.jackhuang.hmcl.util.i18n.I18n.i18n;

Expand Down Expand Up @@ -63,8 +64,10 @@ public HelpPage() {

private void loadHelp() {
showSpinner();
Task.<List<HelpCategory>>supplyAsync(() -> HttpRequest.GET("https://docs.hmcl.net/index.json").getJson(new TypeToken<List<HelpCategory>>() {
}.getType()))

String url = getHelpUrlForLocale(Locale.getDefault());

Task.<List<HelpCategory>>supplyAsync(() -> HttpRequest.GET(url).getJson(new TypeToken<List<HelpCategory>>() {}.getType()))
.thenAcceptAsync(Schedulers.javafx(), helpCategories -> {
for (HelpCategory category : helpCategories) {
ComponentList categoryPane = new ComponentList();
Expand All @@ -78,13 +81,25 @@ private void loadHelp() {
categoryPane.getContent().add(item);
}

content.getChildren().add(ComponentList.createComponentListTitle(category.title));
content.getChildren().add(ComponentList.createComponentListTitle(category.getTitle()));
content.getChildren().add(categoryPane);
}
hideSpinner();
}).start();
}

private String getHelpUrlForLocale(Locale locale) {
if (locale.toString().equals("zh_TW")) {
return "https://docs.hmcl.net/index_zh_TW.json";
}
else if (locale.toString().equals("zh_CN")) {
return "https://docs.hmcl.net/index.json";
}
else {
return "https://docs.hmcl.net/index-en_US.json";
}
}

private static class HelpCategory {
@SerializedName("title")
private final String title;
Expand Down