Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
15 changes: 15 additions & 0 deletions HMCL/src/main/java/org/jackhuang/hmcl/setting/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,21 @@ public void setPromptedVersion(String promptedVersion) {
this.promptedVersion.set(promptedVersion);
}

@SerializedName("translateModDescription")
private final BooleanProperty translateModDescription = new SimpleBooleanProperty(false);

public BooleanProperty translateModDescriptionProperty() {
return translateModDescription;
}

public boolean getmodDescriptionTranslation() {
return translateModDescription.get();
}

public void setmodDescriptionTranslation(boolean translateModDescription) {
this.translateModDescription.set(translateModDescription);
}

@SerializedName("acceptPreviewUpdate")
private final BooleanProperty acceptPreviewUpdate = new SimpleBooleanProperty(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ private static Label createTagLabel(String tag) {
private final StringProperty title = new SimpleStringProperty(this, "title");
private final ObservableList<Label> tags = FXCollections.observableArrayList();
private final StringProperty subtitle = new SimpleStringProperty(this, "subtitle");
private final Label lblSubtitle;
private final Label lblTitle;

private final AggregatedObservableList<Node> firstLineChildren;

Expand All @@ -59,7 +61,7 @@ public TwoLineListItem() {
HBox firstLine = new HBox();
firstLine.getStyleClass().add("first-line");

Label lblTitle = new Label();
lblTitle = new Label();
lblTitle.getStyleClass().add("title");
lblTitle.textProperty().bind(title);

Expand All @@ -68,7 +70,7 @@ public TwoLineListItem() {
firstLineChildren.appendList(tags);
Bindings.bindContent(firstLine.getChildren(), firstLineChildren.getAggregatedList());

Label lblSubtitle = new Label();
lblSubtitle = new Label();
lblSubtitle.getStyleClass().add("subtitle");
lblSubtitle.textProperty().bind(subtitle);

Expand Down Expand Up @@ -109,6 +111,10 @@ public void setSubtitle(String subtitle) {
this.subtitle.set(subtitle);
}

public void setSubtitleWarp(boolean warp) {
lblSubtitle.setWrapText(warp);
}

public void addTag(String tag) {
Label tagLabel = createTagLabel(tag);
tagLabel.getStyleClass().add("tag");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public SettingsPage() {
selectedItemPropertyFor(cboLanguage).bindBidirectional(config().localizationProperty());

disableAutoGameOptionsPane.selectedProperty().bindBidirectional(config().disableAutoGameOptionsProperty());
autoTranslateModDescriptionOptionsPane.selectedProperty().bindBidirectional(config().translateModDescriptionProperty());
// ====

fileCommonLocation.selectedDataProperty().bindBidirectional(config().commonDirTypeProperty());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
public abstract class SettingsView extends StackPane {
protected final JFXComboBox<SupportedLocale> cboLanguage;
protected final OptionToggleButton disableAutoGameOptionsPane;
protected final OptionToggleButton autoTranslateModDescriptionOptionsPane;
protected final MultiFileItem<EnumCommonDirectory> fileCommonLocation;
protected final ComponentSublist fileCommonLocationSublist;
protected final Label lblUpdate;
Expand Down Expand Up @@ -212,6 +213,13 @@ else if (locale.isSameLanguage(currentLocale))
settingsPane.getContent().add(disableAutoGameOptionsPane);
}

{
autoTranslateModDescriptionOptionsPane = new OptionToggleButton();
autoTranslateModDescriptionOptionsPane.setTitle(i18n("settings.launcher.translate_mod_description"));

settingsPane.getContent().add(autoTranslateModDescriptionOptionsPane);
}

{
BorderPane debugPane = new BorderPane();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
import static org.jackhuang.hmcl.ui.FXUtils.stringConverter;
import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
import static org.jackhuang.hmcl.util.javafx.ExtendedProperties.selectedItemPropertyFor;
import static org.jackhuang.hmcl.util.logging.Logger.LOG;

public class DownloadListPage extends Control implements DecoratorPage, VersionPage.VersionLoadable {
protected final ReadOnlyObjectWrapper<State> state = new ReadOnlyObjectWrapper<>();
Expand Down Expand Up @@ -544,7 +545,19 @@ protected void updateControl(RemoteMod dataItem, boolean empty) {
if (empty) return;
ModTranslations.Mod mod = ModTranslations.getTranslationsByRepositoryType(getSkinnable().repository.getType()).getModByCurseForgeId(dataItem.getSlug());
content.setTitle(mod != null && I18n.isUseChinese() ? mod.getDisplayName() : dataItem.getTitle());
content.setSubtitle(dataItem.getDescription());
String orignalDescription = dataItem.getDescription();
if (ModDescriptionTranslation.enabled()) {
ModDescriptionTranslation.translate(dataItem).whenComplete(Schedulers.javafx(), (result, exception) -> {
if (exception != null) {
LOG.warning("Failed to translate mod description", exception);
content.setSubtitle(orignalDescription);
return;
}
content.setSubtitle(result.translated);
}).start();
} else {
content.setSubtitle(orignalDescription);
}
content.getTags().clear();
dataItem.getCategories().stream()
.map(category -> getSkinnable().getLocalizedCategory(category))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@

import static org.jackhuang.hmcl.ui.FXUtils.onEscPressed;
import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
import static org.jackhuang.hmcl.util.logging.Logger.LOG;

public class DownloadPage extends Control implements DecoratorPage {
private final ReadOnlyObjectWrapper<State> state = new ReadOnlyObjectWrapper<>();
Expand Down Expand Up @@ -230,7 +231,21 @@ protected ModDownloadPageSkin(DownloadPage control) {
HBox.setHgrow(content, Priority.ALWAYS);
ModTranslations.Mod mod = getSkinnable().translations.getModByCurseForgeId(getSkinnable().addon.getSlug());
content.setTitle(mod != null && I18n.isUseChinese() ? mod.getDisplayName() : getSkinnable().addon.getTitle());
content.setSubtitle(getSkinnable().addon.getDescription());
String orignalDescription = getSkinnable().addon.getDescription();
if (ModDescriptionTranslation.enabled()) {
ModDescriptionTranslation.translate(getSkinnable().addon).whenComplete(Schedulers.javafx(), (result, exception) -> {
if (exception != null) {
LOG.warning("Failed to translate mod description", exception);
content.setSubtitle(orignalDescription);
return;
}
FXUtils.installFastTooltip(descriptionPane, orignalDescription);
content.setSubtitle(result.translated);
}).start();
} else {
content.setSubtitle(orignalDescription);
}
content.setSubtitleWarp(true);
getSkinnable().addon.getCategories().stream()
.map(category -> getSkinnable().page.getLocalizedCategory(category))
.forEach(content::addTag);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.jackhuang.hmcl.ui.versions;

import org.jackhuang.hmcl.mod.RemoteMod;
import org.jackhuang.hmcl.mod.curse.CurseAddon;
import org.jackhuang.hmcl.mod.modrinth.ModrinthRemoteModRepository;
import org.jackhuang.hmcl.task.CacheFileTask;
import org.jackhuang.hmcl.task.Task;
import org.jackhuang.hmcl.util.gson.JsonSerializable;
import org.jackhuang.hmcl.util.gson.JsonUtils;
import org.jackhuang.hmcl.util.i18n.I18n;

import static org.jackhuang.hmcl.setting.ConfigHolder.config;

public final class ModDescriptionTranslation {
public static final String API_ROOT = "https://mod.mcimirror.top/translate/";

private ModDescriptionTranslation() {
}

public static Task<Response> translate(RemoteMod mod) {
String url;
if (mod.getData() instanceof CurseAddon) {
url = API_ROOT + "curseforge/" + mod.getSlug();
} else if (mod.getData() instanceof ModrinthRemoteModRepository.ProjectSearchResult project) {
url = API_ROOT + "modrinth/" + project.getProjectId();
} else if (mod.getData() instanceof ModrinthRemoteModRepository.Project project) {
url = API_ROOT + "modrinth/" + project.getId();
} else {
throw new AssertionError();
}
return new CacheFileTask(url).thenApplyAsync(path -> JsonUtils.fromJsonFile(path, Response.class));
}

public static boolean enabled() {
return config().getmodDescriptionTranslation() && I18n.isUseChinese();
}

@JsonSerializable
public static class Response {
String translated;
}
}
1 change: 1 addition & 0 deletions HMCL/src/main/resources/assets/lang/I18N.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1355,6 +1355,7 @@ settings.launcher.appearance=Appearance
settings.launcher.common_path.tooltip=HMCL will put all game assets and dependencies here. If there are existing libraries in the game directory, then HMCL will prefer to use them first.
settings.launcher.debug=Debug
settings.launcher.disable_auto_game_options=Do not switch game language
settings.launcher.translate_mod_description=(Chinese only) Auto translate mod descriptions
settings.launcher.download=Download
settings.launcher.download.threads=Threads
settings.launcher.download.threads.auto=Automatically Determine
Expand Down
1 change: 1 addition & 0 deletions HMCL/src/main/resources/assets/lang/I18N_zh.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1143,6 +1143,7 @@ settings.launcher.appearance=外觀
settings.launcher.common_path.tooltip=啟動器將所有遊戲資源及相依元件庫檔案放於此集中管理。如果遊戲目錄內有現成的將不會使用公共庫檔案。
settings.launcher.debug=除錯
settings.launcher.disable_auto_game_options=不自動切換遊戲語言
settings.launcher.translate_mod_description=自動翻譯模組簡介
settings.launcher.download=下載
settings.launcher.download.threads=執行緒數
settings.launcher.download.threads.auto=自動選取執行緒數
Expand Down
1 change: 1 addition & 0 deletions HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1153,6 +1153,7 @@ settings.launcher.appearance=外观
settings.launcher.common_path.tooltip=启动器将所有游戏资源及依赖库文件存放于此集中管理。如果游戏文件夹内有现成的将不会使用公共库文件。
settings.launcher.debug=调试
settings.launcher.disable_auto_game_options=不自动切换游戏语言
settings.launcher.translate_mod_description=自动翻译模组简介
settings.launcher.download=下载
settings.launcher.download.threads=线程数
settings.launcher.download.threads.auto=自动选择线程数
Expand Down