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
16 changes: 16 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 @@ -235,6 +235,22 @@ public void setLocalization(SupportedLocale localization) {
this.localization.set(localization);
}

@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("promptedVersion")
private final StringProperty promptedVersion = new SimpleStringProperty();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ public static Label createTagLabel(String tag) {

private final AggregatedObservableList<Node> firstLineChildren;

private final Label lblTitle;
private final Label lblSubtitle;

public TwoLineListItem(String titleString, String subtitleString) {
this();

Expand All @@ -60,7 +63,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 @@ -69,7 +72,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 @@ -118,6 +121,14 @@ public ObservableList<Label> getTags() {
return tags;
}

public Label getTitleLabel() {
return lblTitle;
}

public Label getSubtitleLabel() {
return lblSubtitle;
}

@Override
public String toString() {
return getTitle();
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());
translateModDescriptionOptionsPane.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 translateModDescriptionOptionsPane;
protected final MultiFileItem<EnumCommonDirectory> fileCommonLocation;
protected final ComponentSublist fileCommonLocationSublist;
protected final Label lblUpdate;
Expand Down Expand Up @@ -202,6 +203,13 @@ else if (locale.isSameLanguage(currentLocale))
settingsPane.getContent().add(disableAutoGameOptionsPane);
}

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

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

{
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 @@ -541,7 +542,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 @@ -228,7 +229,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.getSubtitleLabel().setWrapText(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,40 @@
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 java.util.Locale;

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

public final class ModDescriptionTranslation {
private ModDescriptionTranslation() {
}

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

public static boolean enabled() {
return config().getmodDescriptionTranslation() && I18n.getLocale().getLocale() == Locale.SIMPLIFIED_CHINESE;
}

@JsonSerializable
public static class Response {
String translated;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public Mod getModById(String id) {
public List<Mod> searchMod(String query) {
if (!loadKeywords()) return Collections.emptyList();

StringBuilder newQuery = ((CharSequence) query).chars()
StringBuilder newQuery = query.chars()
.filter(ch -> !Character.isSpaceChar(ch))
.collect(StringBuilder::new, (sb, value) -> sb.append((char) value), StringBuilder::append);
query = newQuery.toString();
Expand Down
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 @@ -1348,6 +1348,7 @@ settings.launcher=Launcher Settings
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.translate_mod_description=(Simplified Chinese only) Translate mod descriptions
settings.launcher.disable_auto_game_options=Do not switch game language
settings.launcher.download=Download
settings.launcher.download.threads=Threads
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 @@ -1137,6 +1137,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 @@ -1147,6 +1147,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