Compare commits
4
Commits
v3.8.0.304
..
v3.7.3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d0145d53d7 | ||
|
|
ee0ae6e4ec | ||
|
|
210ab077cb | ||
|
|
341c60b0de |
No files matched your search
@@ -19,9 +19,6 @@ hmcl-exported-logs-*
|
||||
/.local/
|
||||
/.cache/
|
||||
|
||||
# IANA Language Subtag Registry
|
||||
language-subtag-registry
|
||||
|
||||
# gradle build
|
||||
/build/
|
||||
/HMCL/build/
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
// Copy from https://github.com/sshahine/JFoenix/blob/d427fd801a338f934307ba41ce604eb5c79f0b20/jfoenix/src/main/java/com/jfoenix/skins/JFXListViewSkin.java
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package com.jfoenix.skins;
|
||||
|
||||
import com.jfoenix.adapters.skins.ListViewSkin;
|
||||
import com.jfoenix.controls.JFXListView;
|
||||
import com.jfoenix.effects.JFXDepthManager;
|
||||
import javafx.scene.control.ListCell;
|
||||
import javafx.scene.control.skin.VirtualFlow;
|
||||
import javafx.scene.layout.Region;
|
||||
|
||||
// https://github.com/HMCL-dev/HMCL/issues/4720
|
||||
public class JFXListViewSkin<T> extends ListViewSkin<T> {
|
||||
|
||||
private final VirtualFlow<ListCell<T>> flow;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public JFXListViewSkin(final JFXListView<T> listView) {
|
||||
super(listView);
|
||||
flow = (VirtualFlow<ListCell<T>>) getChildren().get(0);
|
||||
JFXDepthManager.setDepth(flow, listView.depthProperty().get());
|
||||
listView.depthProperty().addListener((o, oldVal, newVal) -> JFXDepthManager.setDepth(flow, newVal));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected double computePrefWidth(double height, double topInset, double rightInset, double bottomInset, double leftInset) {
|
||||
return 200;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected double computePrefHeight(double width, double topInset, double rightInset, double bottomInset, double leftInset) {
|
||||
final int itemsCount = getSkinnable().getItems().size();
|
||||
if (getSkinnable().maxHeightProperty().isBound() || itemsCount <= 0) {
|
||||
return super.computePrefHeight(width, topInset, rightInset, bottomInset, leftInset);
|
||||
}
|
||||
|
||||
final double fixedCellSize = getSkinnable().getFixedCellSize();
|
||||
double computedHeight = fixedCellSize != Region.USE_COMPUTED_SIZE ?
|
||||
fixedCellSize * itemsCount + snapVerticalInsets() : estimateHeight();
|
||||
double height = super.computePrefHeight(width, topInset, rightInset, bottomInset, leftInset);
|
||||
if (height > computedHeight) {
|
||||
height = computedHeight;
|
||||
}
|
||||
|
||||
if (getSkinnable().getMaxHeight() > 0 && computedHeight > getSkinnable().getMaxHeight()) {
|
||||
return getSkinnable().getMaxHeight();
|
||||
}
|
||||
|
||||
return height;
|
||||
}
|
||||
|
||||
private double estimateHeight() {
|
||||
// compute the border/padding for the list
|
||||
double borderWidth = snapVerticalInsets();
|
||||
// compute the gap between list cells
|
||||
|
||||
JFXListView<T> listview = (JFXListView<T>) getSkinnable();
|
||||
double gap = listview.isExpanded() ? ((JFXListView<T>) getSkinnable()).getVerticalGap() * (getSkinnable().getItems()
|
||||
.size()) : 0;
|
||||
// compute the height of each list cell
|
||||
double cellsHeight = 0;
|
||||
for (int i = 0; i < flow.getCellCount(); i++) {
|
||||
ListCell<T> cell = flow.getCell(i);
|
||||
cellsHeight += cell.getHeight();
|
||||
}
|
||||
return cellsHeight + gap + borderWidth;
|
||||
}
|
||||
|
||||
private double snapVerticalInsets() {
|
||||
return getSkinnable().snappedBottomInset() + getSkinnable().snappedTopInset();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -44,7 +44,6 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.jackhuang.hmcl.util.logging.Logger.LOG;
|
||||
@@ -66,7 +65,15 @@ public final class TerracottaMetadata {
|
||||
@SerializedName("downloads_CN") List<String> downloadsCN,
|
||||
@SerializedName("links") List<Link> links
|
||||
) {
|
||||
private TerracottaNative of(String classifier) {
|
||||
private @Nullable TerracottaNative of(String classifier) {
|
||||
String hash = this.classifiers.get(classifier);
|
||||
if (hash == null)
|
||||
return null;
|
||||
|
||||
if (!hash.startsWith("sha256:"))
|
||||
throw new IllegalArgumentException(String.format("Invalid hash value %s for classifier %s.", hash, classifier));
|
||||
hash = hash.substring("sha256:".length());
|
||||
|
||||
List<URI> links = new ArrayList<>(this.downloads.size() + this.downloadsCN.size());
|
||||
for (String download : LocaleUtils.IS_CHINA_MAINLAND
|
||||
? Lang.merge(this.downloadsCN, this.downloads)
|
||||
@@ -74,12 +81,6 @@ public final class TerracottaMetadata {
|
||||
links.add(URI.create(download.replace("${version}", this.latest).replace("${classifier}", classifier)));
|
||||
}
|
||||
|
||||
String hash = Objects.requireNonNull(this.classifiers.get(classifier), String.format("Classifier %s doesn't exist.", classifier));
|
||||
if (!hash.startsWith("sha256:")) {
|
||||
throw new IllegalArgumentException(String.format("Invalid hash value %s for classifier %s.", hash, classifier));
|
||||
}
|
||||
hash = hash.substring("sha256:".length());
|
||||
|
||||
return new TerracottaNative(
|
||||
Collections.unmodifiableList(links),
|
||||
Metadata.DEPENDENCIES_DIRECTORY.resolve(
|
||||
@@ -143,36 +144,31 @@ public final class TerracottaMetadata {
|
||||
|
||||
@Nullable
|
||||
private static ProviderContext locateProvider(Config config) {
|
||||
String architecture = switch (Architecture.SYSTEM_ARCH) {
|
||||
case X86_64 -> "x86_64";
|
||||
case ARM64 -> "arm64";
|
||||
default -> null;
|
||||
};
|
||||
if (architecture == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String arch = Architecture.SYSTEM_ARCH.getCheckedName();
|
||||
return switch (OperatingSystem.CURRENT_OS) {
|
||||
case WINDOWS -> {
|
||||
if (OperatingSystem.SYSTEM_VERSION.isAtLeast(OSVersion.WINDOWS_8_1)) {
|
||||
yield new ProviderContext(
|
||||
new GeneralProvider(config.of(String.format("windows-%s.exe", architecture))),
|
||||
"windows", architecture
|
||||
);
|
||||
}
|
||||
yield null;
|
||||
if (!OperatingSystem.SYSTEM_VERSION.isAtLeast(OSVersion.WINDOWS_8_1))
|
||||
yield null;
|
||||
|
||||
TerracottaNative target = config.of("windows-%s.exe".formatted(arch));
|
||||
yield target != null
|
||||
? new ProviderContext(new GeneralProvider(target), "windows", arch)
|
||||
: null;
|
||||
}
|
||||
case LINUX -> {
|
||||
TerracottaNative target = config.of("linux-%s".formatted(arch));
|
||||
yield target != null
|
||||
? new ProviderContext(new GeneralProvider(target), "linux", arch)
|
||||
: null;
|
||||
}
|
||||
case MACOS -> {
|
||||
TerracottaNative installer = config.of("macos-%s.pkg".formatted(arch));
|
||||
TerracottaNative binary = config.of("macos-%s".formatted(arch));
|
||||
|
||||
yield installer != null && binary != null
|
||||
? new ProviderContext(new MacOSProvider(installer, binary), "macos", arch)
|
||||
: null;
|
||||
}
|
||||
case LINUX -> new ProviderContext(
|
||||
new GeneralProvider(config.of(String.format("linux-%s", architecture))),
|
||||
"linux", architecture
|
||||
);
|
||||
case MACOS -> new ProviderContext(
|
||||
new MacOSProvider(
|
||||
config.of(String.format("macos-%s.pkg", architecture)),
|
||||
config.of(String.format("macos-%s", architecture))
|
||||
),
|
||||
"macos", architecture
|
||||
);
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -69,6 +69,7 @@ public enum SVG {
|
||||
FOR_YOU("M12 12Q14.025 12 16.225 11.5875T20 10.5V20.5Q18.5 21.175 16.35 21.5875T12 22Q9.8 22 7.65 21.5875T4 20.5V10.5Q5.575 11.175 7.775 11.5875T12 12ZM18 19V13.25Q16.75 13.6 15.1125 13.8T12 14Q10.525 14 8.8875 13.8T6 13.25V19Q7.25 19.45 8.875 19.725T12 20Q13.5 20 15.125 19.725T18 19ZM12 2Q13.65 2 14.825 3.175T16 6Q16 7.65 14.825 8.825T12 10Q10.35 10 9.175 8.825T8 6Q8 4.35 9.175 3.175T12 2ZM12 8Q12.825 8 13.4125 7.4125T14 6Q14 5.175 13.4125 4.5875T12 4Q11.175 4 10.5875 4.5875T10 6Q10 6.825 10.5875 7.4125T12 8ZM12 6ZM12 16.625Z"),
|
||||
GAMEPAD("M12 7.65ZM16.35 12ZM7.65 12ZM12 16.35ZM12 10.5 9 7.5V2H15V7.5L12 10.5ZM16.5 15 13.5 12 16.5 9H22V15H16.5ZM2 15V9H7.5L10.5 12 7.5 15H2ZM9 22V16.5L12 13.5 15 16.5V22H9ZM12 7.65 13 6.65V4H11V6.65L12 7.65ZM4 13H6.65L7.65 12 6.65 11H4V13ZM11 20H13V17.35L12 16.35 11 17.35V20ZM17.35 13H20V11H17.35L16.35 12 17.35 13Z"),
|
||||
GLOBE_BOOK("M3.075 13Q3.05 12.75 3.0375 12.5T3.025 12Q3.025 10.125 3.725 8.4875T5.65 5.6375Q6.875 4.425 8.5 3.7125T12 3Q13.875 3 15.5125 3.7125T18.3625 5.6375Q19.575 6.85 20.2875 8.4875T21 12Q21 12.25 20.9875 12.5T20.95 13H18.925Q18.975 12.75 18.9875 12.5T19 12Q19 11.75 18.9875 11.5T18.925 11H15.975Q16 11.25 16 11.5V12.5Q16 12.75 15.975 13H14V12.175Q14 11.875 13.9875 11.575T13.95 11H10.075Q10.05 11.275 10.0375 11.575T10.025 12.175V13H8.05Q8.025 12.75 8.025 12.5V11.5Q8.025 11.25 8.05 11H5.1Q5.05 11.25 5.0375 11.5T5.025 12Q5.025 12.25 5.0375 12.5T5.1 13H3.075ZM5.7 9H8.275Q8.475 7.925 8.775 7.0625T9.425 5.5Q8.225 5.95 7.25 6.8625T5.7 9ZM10.35 9H13.65Q13.4 7.925 13.025 6.9T12 5Q11.35 5.875 10.9625 6.9T10.35 9ZM15.75 9H18.325Q17.75 7.775 16.7625 6.8625T14.575 5.5Q14.925 6.25 15.2375 7.0875T15.75 9ZM11 21V20Q11 18.75 10.125 17.875T8 17H2V15H8Q9.2 15 10.2375 15.525T12 17Q12.725 16.05 13.7625 15.525T16 15H22V17H16Q14.75 17 13.875 17.875T13 20V21H11Z"),
|
||||
GRAPH2("M5 22q-1.25 0-2.125-.875T2 19q0-.975.5625-1.75T4 16.175V14q0-1.25.875-2.125T7 11h4V7.825q-.875-.3-1.4375-1.075T9 5q0-1.25.875-2.125T12 2t2.125.875T15 5q0 .975-.5625 1.75T13 7.825V11h4q1.25 0 2.125.875T20 14v2.175q.875.3 1.4375 1.075T22 19q0 1.25-.875 2.125T19 22t-2.125-.875T16 19q0-.975.5625-1.75T18 16.175V14q0-.425-.2875-.7125T17 13H13v3.175q.875.3 1.4375 1.075T15 19q0 1.25-.875 2.125T12 22t-2.125-.875T9 19q0-.975.5625-1.75T11 16.175V13H7q-.425 0-.7125.2875T6 14v2.175q.875.3 1.4375 1.075T8 19q0 1.25-.875 2.125T5 22Zm0-2q.425 0 .7125-.2875T6 19q0-.425-.2875-.7125T5 18q-.425 0-.7125.2875T4 19q0 .425.2875.7125T5 20Zm7 0q.425 0 .7125-.2875T13 19q0-.425-.2875-.7125T12 18q-.425 0-.7125.2875T11 19q0 .425.2875.7125T12 20Zm7 0q.425 0 .7125-.2875T20 19q0-.425-.2875-.7125T19 18q-.425 0-.7125.2875T18 19q0 .425.2875.7125T19 20ZM12 6q.425 0 .7125-.2875T13 5q0-.425-.2875-.7125T12 4q-.425 0-.7125.2875T11 5q0 .425.2875.7125T12 6Z"),
|
||||
HELP("M11.95 18Q12.475 18 12.8375 17.6375T13.2 16.75Q13.2 16.225 12.8375 15.8625T11.95 15.5Q11.425 15.5 11.0625 15.8625T10.7 16.75Q10.7 17.275 11.0625 17.6375T11.95 18ZM11.05 14.15H12.9Q12.9 13.325 13.0875 12.85T14.15 11.55Q14.8 10.9 15.175 10.3125T15.55 8.9Q15.55 7.5 14.525 6.75T12.1 6Q10.675 6 9.7875 6.75T8.55 8.55L10.2 9.2Q10.325 8.75 10.7625 8.225T12.1 7.7Q12.9 7.7 13.3 8.1375T13.7 9.1Q13.7 9.6 13.4 10.0375T12.65 10.85Q11.55 11.825 11.3 12.325T11.05 14.15ZM12 22Q9.925 22 8.1 21.2125T4.925 19.075Q3.575 17.725 2.7875 15.9T2 12Q2 9.925 2.7875 8.1T4.925 4.925Q6.275 3.575 8.1 2.7875T12 2Q14.075 2 15.9 2.7875T19.075 4.925Q20.425 6.275 21.2125 8.1T22 12Q22 14.075 21.2125 15.9T19.075 19.075Q17.725 20.425 15.9 21.2125T12 22ZM12 20Q15.35 20 17.675 17.675T20 12Q20 8.65 17.675 6.325T12 4Q8.65 4 6.325 6.325T4 12Q4 15.35 6.325 17.675T12 20ZM12 12Z"),
|
||||
HOME("M6 19H9V13H15V19H18V10L12 5.5 6 10V19ZM4 21V9L12 3 20 9V21H13V15H11V21H4ZM12 12.25Z"),
|
||||
HOST("M4 21Q3.175 21 2.5875 20.4125T2 19V5Q2 4.175 2.5875 3.5875T4 3H9Q9.825 3 10.4125 3.5875T11 5V19Q11 19.825 10.4125 20.4125T9 21H4ZM15 21Q14.175 21 13.5875 20.4125T13 19V5Q13 4.175 13.5875 3.5875T15 3H20Q20.825 3 21.4125 3.5875T22 5V19Q22 19.825 21.4125 20.4125T20 21H15ZM4 19H9V5H4V19ZM15 19H20V5H15V19ZM5 15H8V13H5V15ZM16 15H19V13H16V15ZM5 12H8V10H5V12ZM16 12H19V10H16V12ZM5 9H8V7H5V9ZM16 9H19V7H16V9ZM4 19H9 4ZM15 19H20 15Z"),
|
||||
|
||||
@@ -22,24 +22,17 @@ import com.jfoenix.controls.JFXDialogLayout;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.ProgressIndicator;
|
||||
import javafx.scene.control.ScrollPane;
|
||||
import org.jackhuang.hmcl.Metadata;
|
||||
import org.jackhuang.hmcl.task.Schedulers;
|
||||
import org.jackhuang.hmcl.task.Task;
|
||||
import org.jackhuang.hmcl.ui.construct.DialogCloseEvent;
|
||||
import org.jackhuang.hmcl.ui.construct.JFXHyperlink;
|
||||
import org.jackhuang.hmcl.upgrade.RemoteVersion;
|
||||
import org.jackhuang.hmcl.util.versioning.VersionNumber;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.jsoup.nodes.Node;
|
||||
import org.jsoup.nodes.TextNode;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.jackhuang.hmcl.Metadata.CHANGELOG_URL;
|
||||
import static org.jackhuang.hmcl.ui.FXUtils.onEscPressed;
|
||||
@@ -47,26 +40,6 @@ import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
|
||||
import static org.jackhuang.hmcl.util.logging.Logger.LOG;
|
||||
|
||||
public final class UpgradeDialog extends JFXDialogLayout {
|
||||
|
||||
private static final Pattern CHANGELOG_TITLE_PATTERN = Pattern.compile("HMCL (?<version>\\d(?:\\.\\d+)+)");
|
||||
|
||||
private static @Nullable VersionNumber extractVersionNumber(Node node) {
|
||||
String text;
|
||||
if (node instanceof Element element) {
|
||||
text = element.text();
|
||||
} else if (node instanceof TextNode textNode) {
|
||||
text = textNode.text();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
Matcher matcher = CHANGELOG_TITLE_PATTERN.matcher(text);
|
||||
if (matcher.find())
|
||||
return VersionNumber.asVersion(matcher.group("version"));
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
public UpgradeDialog(RemoteVersion remoteVersion, Runnable updateRunnable) {
|
||||
maxWidthProperty().bind(Controllers.getScene().widthProperty().multiply(0.7));
|
||||
maxHeightProperty().bind(Controllers.getScene().heightProperty().multiply(0.7));
|
||||
@@ -76,14 +49,7 @@ public final class UpgradeDialog extends JFXDialogLayout {
|
||||
|
||||
String url = CHANGELOG_URL + remoteVersion.getChannel().channelName + ".html";
|
||||
boolean isPreview = remoteVersion.isPreview();
|
||||
|
||||
Task.supplyAsync(Schedulers.io(), () -> {
|
||||
VersionNumber targetVersion = VersionNumber.asVersion(remoteVersion.getVersion());
|
||||
VersionNumber currentVersion = VersionNumber.asVersion(Metadata.VERSION);
|
||||
if (targetVersion.compareTo(currentVersion) <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Document document = Jsoup.parse(new URL(url), 30 * 1000);
|
||||
String id = null;
|
||||
Node node = null;
|
||||
@@ -99,26 +65,14 @@ public final class UpgradeDialog extends JFXDialogLayout {
|
||||
if (node == null || !"h1".equals(node.nodeName()))
|
||||
throw new IOException("Cannot find current changelog in document");
|
||||
|
||||
VersionNumber changelogVersion = extractVersionNumber(node);
|
||||
if (changelogVersion == null)
|
||||
throw new IOException("Cannot find current changelog in document. The node: " + node);
|
||||
|
||||
if (!targetVersion.equals(changelogVersion)) {
|
||||
LOG.warning("The changelog has not been updated yet. Expected: " + targetVersion + ", Actual: " + changelogVersion);
|
||||
return null;
|
||||
}
|
||||
|
||||
HTMLRenderer renderer = new HTMLRenderer(uri -> {
|
||||
LOG.info("Open link: " + uri);
|
||||
FXUtils.openLink(uri.toString());
|
||||
});
|
||||
|
||||
do {
|
||||
if ("h1".equals(node.nodeName())) {
|
||||
changelogVersion = extractVersionNumber(node);
|
||||
if (changelogVersion == null || changelogVersion.compareTo(currentVersion) <= 0) {
|
||||
break;
|
||||
}
|
||||
if ("h1".equals(node.nodeName()) && !id.equals(node.attr("id"))) {
|
||||
break;
|
||||
}
|
||||
renderer.appendNode(node);
|
||||
node = node.nextSibling();
|
||||
@@ -128,14 +82,10 @@ public final class UpgradeDialog extends JFXDialogLayout {
|
||||
return renderer.render();
|
||||
}).whenComplete(Schedulers.javafx(), (result, exception) -> {
|
||||
if (exception == null) {
|
||||
if (result != null) {
|
||||
ScrollPane scrollPane = new ScrollPane(result);
|
||||
scrollPane.setFitToWidth(true);
|
||||
FXUtils.smoothScrolling(scrollPane);
|
||||
setBody(scrollPane);
|
||||
} else {
|
||||
setBody();
|
||||
}
|
||||
ScrollPane scrollPane = new ScrollPane(result);
|
||||
scrollPane.setFitToWidth(true);
|
||||
FXUtils.smoothScrolling(scrollPane);
|
||||
setBody(scrollPane);
|
||||
} else {
|
||||
LOG.warning("Failed to load update log, trying to open it in browser");
|
||||
FXUtils.openLink(url);
|
||||
|
||||
@@ -28,7 +28,6 @@ import javafx.scene.layout.VBox;
|
||||
import org.jackhuang.hmcl.task.*;
|
||||
import org.jackhuang.hmcl.ui.FXUtils;
|
||||
import org.jackhuang.hmcl.util.TaskCancellationAction;
|
||||
import org.jackhuang.hmcl.util.i18n.I18n;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Optional;
|
||||
@@ -87,7 +86,18 @@ public class TaskExecutorDialogPane extends BorderPane {
|
||||
});
|
||||
|
||||
speedEventHandler = FetchTask.SPEED_EVENT.registerWeak(speedEvent -> {
|
||||
String message = I18n.formatSpeed(speedEvent.getSpeed());
|
||||
String unit = "B/s";
|
||||
double speed = speedEvent.getSpeed();
|
||||
if (speed > 1024) {
|
||||
speed /= 1024;
|
||||
unit = "KiB/s";
|
||||
}
|
||||
if (speed > 1024) {
|
||||
speed /= 1024;
|
||||
unit = "MiB/s";
|
||||
}
|
||||
|
||||
String message = String.format("%.1f %s", speed, unit);
|
||||
Platform.runLater(() -> lblProgress.setText(message));
|
||||
});
|
||||
|
||||
|
||||
@@ -138,11 +138,8 @@ public final class AboutPage extends StackPane {
|
||||
else if (obj.has("subtitleLocalized"))
|
||||
item.setSubtitle(i18n(obj.get("subtitleLocalized").getAsString()));
|
||||
|
||||
if (obj.has("externalLink")) {
|
||||
String link = obj.get("externalLink").getAsString();
|
||||
item.setExternalLink(link);
|
||||
FXUtils.installFastTooltip(item.getExternalLinkButton(), link);
|
||||
}
|
||||
if (obj.has("externalLink"))
|
||||
item.setExternalLink(obj.get("externalLink").getAsString());
|
||||
|
||||
componentList.getContent().add(item);
|
||||
}
|
||||
|
||||
@@ -183,7 +183,7 @@ public class RootPage extends DecoratorAnimatedPage implements DecoratorPage {
|
||||
|
||||
// sixth item in left sidebar
|
||||
AdvancedListItem terracottaItem = new AdvancedListItem();
|
||||
terracottaItem.setLeftGraphic(wrap(SVG.HOST));
|
||||
terracottaItem.setLeftGraphic(wrap(SVG.GRAPH2));
|
||||
terracottaItem.setActionButtonVisible(false);
|
||||
terracottaItem.setTitle(i18n("terracotta"));
|
||||
terracottaItem.setOnAction(e -> Controllers.navigate(Controllers.getTerracottaPage()));
|
||||
@@ -198,7 +198,8 @@ public class RootPage extends DecoratorAnimatedPage implements DecoratorPage {
|
||||
.add(downloadItem)
|
||||
.startCategory(i18n("settings.launcher.general").toUpperCase(Locale.ROOT))
|
||||
.add(launcherSettingsItem)
|
||||
.add(terracottaItem);
|
||||
.add(terracottaItem)
|
||||
.addNavigationDrawerItem(i18n("chat"), SVG.CHAT, () -> FXUtils.openLink(Metadata.GROUPS_URL));
|
||||
|
||||
// the root page, with the sidebar in left, navigator in center.
|
||||
setLeft(sideBar);
|
||||
|
||||
@@ -24,7 +24,6 @@ import javafx.geometry.Insets;
|
||||
import javafx.scene.layout.BorderPane;
|
||||
import javafx.scene.layout.Priority;
|
||||
import javafx.scene.layout.VBox;
|
||||
import org.jackhuang.hmcl.Metadata;
|
||||
import org.jackhuang.hmcl.game.LauncherHelper;
|
||||
import org.jackhuang.hmcl.setting.Profile;
|
||||
import org.jackhuang.hmcl.setting.Profiles;
|
||||
@@ -90,8 +89,7 @@ public class TerracottaPage extends DecoratorAnimatedPage implements DecoratorPa
|
||||
}, it -> mainPage.getProfile().setSelectedVersion(it.getId()));
|
||||
})
|
||||
.addNavigationDrawerItem(i18n("terracotta.feedback.title"), SVG.FEEDBACK, () -> FXUtils.openLink(TerracottaMetadata.FEEDBACK_LINK))
|
||||
.addNavigationDrawerItem(i18n("terracotta.easytier"), SVG.HOST, () -> FXUtils.openLink("https://easytier.cn/"))
|
||||
.addNavigationDrawerItem(i18n("chat"), SVG.CHAT, () -> FXUtils.openLink(Metadata.GROUPS_URL));
|
||||
.addNavigationDrawerItem(i18n("terracotta.easytier"), SVG.HOST, () -> FXUtils.openLink("https://easytier.cn/"));
|
||||
BorderPane.setMargin(toolbar, new Insets(0, 0, 12, 0));
|
||||
left.setBottom(toolbar);
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import javafx.beans.property.*;
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.layout.BorderPane;
|
||||
import javafx.scene.layout.Priority;
|
||||
import javafx.scene.layout.StackPane;
|
||||
import javafx.scene.layout.VBox;
|
||||
@@ -237,6 +238,10 @@ public class VersionPage extends DecoratorAnimatedPage implements DecoratorPage
|
||||
super(control);
|
||||
|
||||
{
|
||||
BorderPane left = new BorderPane();
|
||||
FXUtils.setLimitWidth(left, 200);
|
||||
setLeft(left);
|
||||
|
||||
AdvancedListItem versionSettingsItem = new AdvancedListItem();
|
||||
versionSettingsItem.getStyleClass().add("navigation-drawer-item");
|
||||
versionSettingsItem.setTitle(i18n("settings.game"));
|
||||
|
||||
@@ -222,14 +222,9 @@ public final class Versions {
|
||||
|
||||
private static boolean checkVersionForLaunching(Profile profile, String id) {
|
||||
if (id == null || !profile.getRepository().isLoaded() || !profile.getRepository().hasVersion(id)) {
|
||||
JFXButton gotoDownload = new JFXButton(i18n("version.empty.launch.goto_download"));
|
||||
gotoDownload.getStyleClass().add("dialog-accept");
|
||||
gotoDownload.setOnAction(e -> Controllers.navigate(Controllers.getDownloadPage()));
|
||||
|
||||
Controllers.confirmAction(i18n("version.empty.launch"), i18n("launch.failed"),
|
||||
MessageDialogPane.MessageType.ERROR,
|
||||
gotoDownload,
|
||||
null);
|
||||
Controllers.dialog(i18n("version.empty.launch"), i18n("launch.failed"), MessageDialogPane.MessageType.ERROR, () -> {
|
||||
Controllers.navigate(Controllers.getDownloadPage());
|
||||
});
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
|
||||
@@ -71,10 +71,6 @@ public final class I18n {
|
||||
return getTranslator().formatDateTime(time);
|
||||
}
|
||||
|
||||
public static String formatSpeed(long bytes) {
|
||||
return getTranslator().formatSpeed(bytes);
|
||||
}
|
||||
|
||||
public static String getDisplaySelfVersion(RemoteVersion version) {
|
||||
return getTranslator().getDisplayVersion(version);
|
||||
}
|
||||
|
||||
@@ -59,13 +59,4 @@ public class Translator {
|
||||
return formatter.format(time);
|
||||
}
|
||||
|
||||
public String formatSpeed(long bytes) {
|
||||
if (bytes < 1024) {
|
||||
return supportedLocale.i18n("download.speed.byte_per_second", bytes);
|
||||
} else if (bytes < 1024 * 1024) {
|
||||
return supportedLocale.i18n("download.speed.kibibyte_per_second", (double) bytes / 1024);
|
||||
} else {
|
||||
return supportedLocale.i18n("download.speed.megabyte_per_second", (double) bytes / (1024 * 1024));
|
||||
}
|
||||
}
|
||||
}
|
||||
+10
-12
@@ -23,20 +23,25 @@ import org.jackhuang.hmcl.util.i18n.SupportedLocale;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.TemporalAccessor;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.jackhuang.hmcl.util.logging.Logger.LOG;
|
||||
|
||||
/// @author Glavo
|
||||
public class Translator_en_Qabs extends Translator {
|
||||
private static final Map<Integer, Integer> MAPPER;
|
||||
private static final DateTimeFormatter BASE_FORMATTER = DateTimeFormatter.ofPattern("MMM d, yyyy, h:mm:ss a")
|
||||
.withZone(ZoneId.systemDefault());
|
||||
|
||||
static {
|
||||
private static final Map<Integer, Integer> MAPPER = loadMap();
|
||||
|
||||
private static Map<Integer, Integer> loadMap() {
|
||||
var map = new LinkedHashMap<Integer, Integer>();
|
||||
|
||||
InputStream inputStream = Translator_en_Qabs.class.getResourceAsStream("/assets/lang/upside_down.txt");
|
||||
if (inputStream != null) {
|
||||
try (inputStream) {
|
||||
@@ -57,7 +62,7 @@ public class Translator_en_Qabs extends Translator {
|
||||
} else {
|
||||
LOG.warning("upside_down.txt not found");
|
||||
}
|
||||
MAPPER = Collections.unmodifiableMap(map);
|
||||
return Collections.unmodifiableMap(map);
|
||||
}
|
||||
|
||||
public static String translate(String str) {
|
||||
@@ -66,8 +71,6 @@ public class Translator_en_Qabs extends Translator {
|
||||
return builder.reverse().toString();
|
||||
}
|
||||
|
||||
private final SupportedLocale originalLocale = SupportedLocale.getLocale(Locale.ENGLISH);
|
||||
|
||||
public Translator_en_Qabs(SupportedLocale locale) {
|
||||
super(locale);
|
||||
}
|
||||
@@ -79,11 +82,6 @@ public class Translator_en_Qabs extends Translator {
|
||||
|
||||
@Override
|
||||
public String formatDateTime(TemporalAccessor time) {
|
||||
return translate(originalLocale.getTranslator().formatDateTime(time));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String formatSpeed(long bytes) {
|
||||
return translate(originalLocale.getTranslator().formatSpeed(bytes));
|
||||
return translate(BASE_FORMATTER.format(time));
|
||||
}
|
||||
}
|
||||
@@ -228,7 +228,7 @@
|
||||
|
||||
.class-title {
|
||||
-fx-font-size: 12px;
|
||||
-fx-padding: 16 16 8 16;
|
||||
-fx-padding: 8 16 8 16;
|
||||
}
|
||||
|
||||
.advanced-list-box-item {
|
||||
|
||||
@@ -359,9 +359,6 @@ download.javafx.notes=We are currently downloading dependencies for HMCL from th
|
||||
Note: If your download speed is too slow, you can try switching to another mirror.
|
||||
download.javafx.component=Downloading module "%s"
|
||||
download.javafx.prepare=Preparing to download
|
||||
download.speed.byte_per_second=%d B/s
|
||||
download.speed.kibibyte_per_second=%.1f KiB/s
|
||||
download.speed.megabyte_per_second=%.1f MiB/s
|
||||
|
||||
exception.access_denied=HMCL is unable to access the file "%s". It may be locked by another process.\n\
|
||||
\n\
|
||||
@@ -1058,7 +1055,7 @@ mods.category=Category
|
||||
mods.channel.alpha=Alpha
|
||||
mods.channel.beta=Beta
|
||||
mods.channel.release=Release
|
||||
mods.check_updates=Update
|
||||
mods.check_updates=Check for Updates
|
||||
mods.check_updates.current_version=Current Version
|
||||
mods.check_updates.empty=All mods are up-to-date
|
||||
mods.check_updates.failed_check=Failed to check for updates.
|
||||
@@ -1529,8 +1526,7 @@ version.name=Instance Name
|
||||
version.cannot_read=Failed to parse the game instance, installation cannot continue.
|
||||
version.empty=No Instances
|
||||
version.empty.add=Add new instance
|
||||
version.empty.launch=No available instances.\nYou can go to the "Download" page to get the game, or switch the game directory in the "All Instances" page.
|
||||
version.empty.launch.goto_download=Go to Download Page
|
||||
version.empty.launch=No available instances. Clicking "OK" will take you to the "Download" page.\n\nYou can also download the game or switch game directories via the "Download" or "All Instances" buttons on the HMCL homepage.
|
||||
version.empty.hint=There are no Minecraft instances here.\nYou can try switching to another game directory or clicking here to download one.
|
||||
version.game.all=All
|
||||
version.game.april_fools=April Fools
|
||||
|
||||
@@ -1061,7 +1061,7 @@ mods.category=Categoría
|
||||
mods.channel.alpha=Alpha
|
||||
mods.channel.beta=Beta
|
||||
mods.channel.release=Release
|
||||
mods.check_updates=Actualizar
|
||||
mods.check_updates=Comprobar actualizaciones
|
||||
mods.check_updates.current_version=Versión actual
|
||||
mods.check_updates.empty=Todos los mods están actualizados
|
||||
mods.check_updates.failed_check=No se ha podido comprobar si hay actualizaciones.
|
||||
@@ -1452,6 +1452,7 @@ version.name=Nombre de instancia
|
||||
version.cannot_read=No se ha podido analizar la instancia del juego, la instalación no puede continuar.
|
||||
version.empty=No hay instancias
|
||||
version.empty.add=Añadir una instancia
|
||||
version.empty.launch=No hay instancias disponibles. Si haces clic en «Aceptar», accederás a la página «Descargar». También puedes descargar el juego o cambiar de directorio de juego con los botones «Descargar» o «Todas las instancias» de la página principal de HMCL.
|
||||
version.empty.hint=No hay instancias de Minecraft aquí.\nPuedes intentar cambiar a otro directorio del juego o hacer clic aquí para descargar una.
|
||||
version.game.all=Todos
|
||||
version.game.april_fools=Día de los Inocentes
|
||||
|
||||
@@ -929,6 +929,7 @@ version=ゲーム
|
||||
version.cannot_read=ゲームのバージョンが見つかりません。自動インストールを続行できません。
|
||||
version.empty=ゲームなし
|
||||
version.empty.add=起動構成を作成
|
||||
version.empty.launch=起動するバージョンがありません。ダウンロードページからバージョンをインストールしてください。
|
||||
version.empty.hint=インストールされているゲームバージョンはありません。新しいゲームをダウンロードするには、ここをクリックしてください。
|
||||
version.game.old=Old
|
||||
version.game.release=リリース
|
||||
|
||||
@@ -1240,6 +1240,7 @@ version.name=戲例之名
|
||||
version.cannot_read=不能閲戲例,無自裝矣
|
||||
version.empty=無游戲例
|
||||
version.empty.add=入引頁以裝戲
|
||||
version.empty.launch=無可啟者。擊「善」入「引」之頁。\n庶擊 HMCL 主頁之左「引」之鈕裝戲,抑更戲之案夾乎「例列」。
|
||||
version.empty.hint=無畢裝者。\n君且更他戲夾,抑擊斯以往戲之引頁。
|
||||
version.game.all=全覽
|
||||
version.game.april_fools=愚人節
|
||||
|
||||
@@ -360,9 +360,6 @@ download.javafx.notes=Скачивание зависимостей для ла
|
||||
Примечание: Если ваша скорость скачивания слишком низкая, вы можете попробовать переключиться на другое зеркало.
|
||||
download.javafx.component=Скачивание модуля «%s»
|
||||
download.javafx.prepare=Подготовка к скачиванию
|
||||
download.speed.byte_per_second=%d Б/сек
|
||||
download.speed.kibibyte_per_second=%.1f КиБ/сек
|
||||
download.speed.megabyte_per_second=%.1f МиБ/сек
|
||||
|
||||
exception.access_denied=Лаунчер не может получить доступ к файлу «%s», возможно он занят другим процессом.\n\
|
||||
\n\
|
||||
@@ -1443,6 +1440,7 @@ version.name=Название сборки
|
||||
version.cannot_read=Невозможно найти версию игры. Невозможно продолжить автоматическую установку.
|
||||
version.empty=Нет сборок
|
||||
version.empty.add=Установить новую сборок
|
||||
version.empty.launch=Нет доступных сборок. Нажав «ОК», вы перейдете на страницу «Скачать»\n\nВы также можете скачать игру или переключить директорию игры с помощью кнопок «Скачать» или «Все сборок» на главной странице HMCL.
|
||||
version.empty.hint=Нет сборок.\nВы можете попробовать перейти в другую папку с игрой или нажать здесь, чтобы скачать игру.
|
||||
version.game.all=Все
|
||||
version.game.april_fools=День смеха
|
||||
|
||||
@@ -356,10 +356,6 @@ download.javafx.notes=Ми зараз завантажуємо залежнос
|
||||
Примітка: Якщо ваша швидкість завантаження занадто повільна, ви можете спробувати переключитися на інше дзеркало.
|
||||
download.javafx.component=Завантаження модуля "%s"
|
||||
download.javafx.prepare=Підготовка до завантаження
|
||||
download.speed.byte_per_second=%d Б/сек
|
||||
download.speed.kibibyte_per_second=%.1f КiБ/сек
|
||||
download.speed.megabyte_per_second=%.1f МiБ/сек
|
||||
|
||||
exception.access_denied=HMCL не може отримати доступ до файлу "%s". Можливо, він заблокований іншим процесом.\n\
|
||||
\n\
|
||||
Для користувачів Windows ви можете відкрити "Монітор ресурсів", щоб перевірити, чи не використовується він іншим процесом. Якщо так, ви можете спробувати знову після завершення цього процесу.\n\
|
||||
@@ -1389,6 +1385,7 @@ version.name=Назва екземпляра
|
||||
version.cannot_read=Не вдалося розібрати екземпляр гри, встановлення не може продовжуватися.
|
||||
version.empty=Немає екземплярів
|
||||
version.empty.add=Додати новий екземпляр
|
||||
version.empty.launch=Немає доступних екземплярів. Натискання "ОК" перенесе вас на сторінку "Завантаження". Ви також можете завантажити гру або змінити ігрові каталоги через кнопки "Завантаження" або "Усі екземпляри" на головній сторінці HMCL.
|
||||
version.empty.hint=Тут немає екземплярів Minecraft. Ви можете спробувати переключитися на інший ігровий каталог або натиснути тут, щоб завантажити один.
|
||||
version.game.all=Усі
|
||||
version.game.april_fools=Перший квітня
|
||||
|
||||
@@ -358,9 +358,6 @@ download.javafx=正在下載必要的執行時元件
|
||||
download.javafx.notes=正在透過網路下載 HMCL 必要的執行時元件。\n點擊「切換下載源」按鈕查看詳情以及選取下載源。點擊「取消」按鈕停止並退出。\n注意:如果下載速度過慢,請嘗試切換下載源。
|
||||
download.javafx.component=正在下載元件「%s」
|
||||
download.javafx.prepare=準備開始下載
|
||||
download.speed.byte_per_second=%d B/s
|
||||
download.speed.kibibyte_per_second=%.1f KiB/s
|
||||
download.speed.megabyte_per_second=%.1f MiB/s
|
||||
|
||||
exception.access_denied=無法存取檔案「%s」。因為 HMCL 沒有對該檔案的訪問權限,或者該檔案已被其他程式開啟。\n\
|
||||
請你檢查目前作業系統帳戶是否能訪存取檔案,比如非管理員使用者可能不能訪問其他帳戶的個人目錄內的檔案。\n\
|
||||
@@ -1313,8 +1310,7 @@ version.name=遊戲實例名稱
|
||||
version.cannot_read=讀取遊戲實例失敗,無法進行自動安裝
|
||||
version.empty=沒有遊戲實例
|
||||
version.empty.add=進入下載頁安裝遊戲
|
||||
version.empty.launch=沒有可啟動的遊戲。\n你可以前往「下載」頁面下載新遊戲,或在「實例清單」切換遊戲目錄。
|
||||
version.empty.launch.goto_download=前往下載頁面
|
||||
version.empty.launch=沒有可啟動的遊戲。點擊「確定」將進入「下載」頁面。\n你也可以點擊 HMCL 主介面左側的「下載」按鈕安裝遊戲,或在「實例清單」切換遊戲目錄。
|
||||
version.empty.hint=沒有已安裝的遊戲。\n你可以切換其他遊戲目錄,或者點擊此處進入遊戲下載頁面。
|
||||
version.game.all=全部
|
||||
version.game.april_fools=愚人節
|
||||
|
||||
@@ -366,9 +366,6 @@ download.javafx=正在下载必要的运行时组件……
|
||||
download.javafx.notes=正在通过网络下载 HMCL 必要的运行时组件。\n点击“切换下载源”按钮查看详情以及选择下载源。点击“取消”按钮停止并退出。\n注意:若下载速度过慢,请尝试切换下载源。
|
||||
download.javafx.component=正在下载模块“%s”
|
||||
download.javafx.prepare=准备开始下载
|
||||
download.speed.byte_per_second=%d B/s
|
||||
download.speed.kibibyte_per_second=%.1f KiB/s
|
||||
download.speed.megabyte_per_second=%.1f MiB/s
|
||||
|
||||
exception.access_denied=无法访问文件“%s”。HMCL 没有对该文件的访问权限,或者该文件已被其他程序打开。\n\
|
||||
请你检查当前操作系统账户是否能访问该文件,比如非管理员用户可能无法访问其他账户的个人文件夹内的文件。\n\
|
||||
@@ -1323,8 +1320,7 @@ version.name=游戏实例名称
|
||||
version.cannot_read=读取游戏实例失败,无法进行自动安装
|
||||
version.empty=没有游戏实例
|
||||
version.empty.add=进入下载页安装游戏
|
||||
version.empty.launch=没有可启动的游戏。\n你可以前往下载页面下载新游戏,或在“实例列表”中切换游戏文件夹。
|
||||
version.empty.launch.goto_download=前往下载页面
|
||||
version.empty.launch=没有可启动的游戏。点击“确定”将进入“下载”页面。\n你也可以点击 HMCL 主界面左侧的“下载”按钮安装游戏,或在“实例列表”切换游戏文件夹。
|
||||
version.empty.hint=没有已安装的游戏。\n你可以切换其他游戏文件夹,或者点击此处进入游戏下载页面。
|
||||
version.game.all=全部
|
||||
version.game.april_fools=愚人节
|
||||
|
||||
@@ -1,18 +1,20 @@
|
||||
{
|
||||
"version_legacy": "0\\.3\\.([89]-rc\\.([0-9]|10)|10)",
|
||||
"version_legacy": "0\\.3\\.([89]-rc\\.([0-9]|10)|10|11)",
|
||||
"version_recent": [
|
||||
"0.3.10"
|
||||
"0.3.11"
|
||||
],
|
||||
"version_latest": "0.3.11",
|
||||
"version_latest": "0.3.12",
|
||||
"classifiers": {
|
||||
"linux-arm64": "sha256:cd321f22b200b212ba21eb7582bfe0e1bcadb528d19c70307a2aea9596118d33",
|
||||
"linux-x86_64": "sha256:d4b15ec7cba7c9332b84f6acbf247e779543f958f9b240e9707bd6f37973e12a",
|
||||
"macos-arm64": "sha256:8456ad2c016e7c5c6f5814d98203a89ec38d13cdaafe94d328e313404ea16a2f",
|
||||
"macos-arm64.pkg": "sha256:f85f86c563d4460ba97ed048fee22fa0e1398454443576c56b0afeebb98e8691",
|
||||
"macos-x86_64": "sha256:cb1f7f5d5876a9177c426bece5ad0845e1b25d3430533646b2b9c93d97d37d79",
|
||||
"macos-x86_64.pkg": "sha256:e54bc35be7c8c543362b1b428e7d40d2116f1a4e57ade1c09cbef6239efb67ae",
|
||||
"windows-arm64.exe": "sha256:40c628bafb48d51c90f47037f8c4caedfadb52421e64b70011f448d1d2f553a3",
|
||||
"windows-x86_64.exe": "sha256:de518b2b4e60336fd272092326799966efc4e72acd65576d83e61d4d242fd61d"
|
||||
"linux-arm64": "sha256:cb88933f539d287419b9a83960bfdd8252dd2a850cbb39008491916c8a8ee25b",
|
||||
"linux-x86_64": "sha256:b329fed4157999f1be504a63ea2f5c95985d440435fba2f3b4604dced340572a",
|
||||
"linux-loongarch64": "sha256:9e6b1beb90817339ca8b40b3e26bd064505cc789d1c5f7df80659d91971042b6",
|
||||
"linux-riscv64": "sha256:58dde78047e3e0317cc935bfa6db0c2c3f6608fea15f545aa83d78a921805fc4",
|
||||
"macos-arm64": "sha256:282f47dd0e2667da44b0bef74a87d41d9e568c224515d2f230d2ef25edb1f628",
|
||||
"macos-arm64.pkg": "sha256:295974ec16d5a69006126d574efe16e7622ab67e85d35cd03020f38670cf3313",
|
||||
"macos-x86_64": "sha256:8cf097ae87b6f8fdb4a3543176ecc526922201446c18170e779ffff0cc62ec01",
|
||||
"macos-x86_64.pkg": "sha256:bfc1f4c121c107b3371b56e83cad80924be9016db3c3b39a9db7ae579dbaf1e2",
|
||||
"windows-arm64.exe": "sha256:cfa93fbc426002dbd25e376457db2a27be101907f568d91e1f92adfcf1b69cb8",
|
||||
"windows-x86_64.exe": "sha256:2153b676295cf059ca2ac08178e1d3754eb0007c947378cd1ae2ef2b9f7a2a4f"
|
||||
},
|
||||
"downloads": [
|
||||
"https://github.com/burningtnt/Terracotta/releases/download/v${version}/terracotta-${version}-${classifier}"
|
||||
|
||||
@@ -17,10 +17,9 @@
|
||||
*/
|
||||
package org.jackhuang.hmcl.task;
|
||||
|
||||
import org.jackhuang.hmcl.util.Lang;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.CompletionException;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
public abstract class CompletableFutureTask<T> extends Task<T> {
|
||||
|
||||
@@ -30,11 +29,18 @@ public abstract class CompletableFutureTask<T> extends Task<T> {
|
||||
|
||||
public abstract CompletableFuture<T> getFuture(TaskCompletableFuture executor);
|
||||
|
||||
protected static Throwable resolveException(Throwable e) {
|
||||
if (e instanceof ExecutionException || e instanceof CompletionException)
|
||||
return resolveException(e.getCause());
|
||||
else
|
||||
return e;
|
||||
}
|
||||
|
||||
public static class CustomException extends RuntimeException {}
|
||||
|
||||
protected static CompletableFuture<Void> breakable(CompletableFuture<?> future) {
|
||||
return future.thenApplyAsync(unused1 -> (Void) null).exceptionally(throwable -> {
|
||||
if (Lang.resolveException(throwable) instanceof CustomException) return null;
|
||||
if (resolveException(throwable) instanceof CustomException) return null;
|
||||
else throw new CompletionException(throwable);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -345,11 +345,16 @@ public abstract class Task<T> {
|
||||
}
|
||||
|
||||
private final ReadOnlyStringWrapper message = new ReadOnlyStringWrapper(this, "message", null);
|
||||
private final InvocationDispatcher<String> messageUpdate = InvocationDispatcher.runOn(Platform::runLater, message::set);
|
||||
|
||||
public final ReadOnlyStringProperty messageProperty() {
|
||||
return message.getReadOnlyProperty();
|
||||
}
|
||||
|
||||
protected final void updateMessage(String newMessage) {
|
||||
messageUpdate.accept(newMessage);
|
||||
}
|
||||
|
||||
public final T run() throws Exception {
|
||||
if (getSignificance().shouldLog())
|
||||
LOG.trace("Executing task: " + getName());
|
||||
|
||||
@@ -17,9 +17,8 @@
|
||||
*/
|
||||
package org.jackhuang.hmcl.util;
|
||||
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.lang.invoke.VarHandle;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/// When [#accept(T)] is called, this class invokes the handler on another thread.
|
||||
@@ -29,16 +28,6 @@ import java.util.function.Consumer;
|
||||
/// @author yushijinhun
|
||||
public final class InvocationDispatcher<T> implements Consumer<T> {
|
||||
|
||||
private static final VarHandle PENDING_ARG_HANDLE;
|
||||
static {
|
||||
try {
|
||||
PENDING_ARG_HANDLE = MethodHandles.lookup()
|
||||
.findVarHandle(InvocationDispatcher.class, "pendingArg", Holder.class);
|
||||
} catch (NoSuchFieldException | IllegalAccessException e) {
|
||||
throw new ExceptionInInitializerError(e);
|
||||
}
|
||||
}
|
||||
|
||||
/// @param executor The executor must dispatch all tasks to a single thread.
|
||||
public static <T> InvocationDispatcher<T> runOn(Executor executor, Consumer<T> action) {
|
||||
return new InvocationDispatcher<>(executor, action);
|
||||
@@ -46,10 +35,7 @@ public final class InvocationDispatcher<T> implements Consumer<T> {
|
||||
|
||||
private final Executor executor;
|
||||
private final Consumer<T> action;
|
||||
|
||||
/// @see #PENDING_ARG_HANDLE
|
||||
@SuppressWarnings("unused")
|
||||
private volatile Holder<T> pendingArg;
|
||||
private final AtomicReference<Holder<T>> pendingArg = new AtomicReference<>();
|
||||
|
||||
private InvocationDispatcher(Executor executor, Consumer<T> action) {
|
||||
this.executor = executor;
|
||||
@@ -58,15 +44,12 @@ public final class InvocationDispatcher<T> implements Consumer<T> {
|
||||
|
||||
@Override
|
||||
public void accept(T t) {
|
||||
if (PENDING_ARG_HANDLE.getAndSet(this, new Holder<>(t)) == null) {
|
||||
if (pendingArg.getAndSet(new Holder<>(t)) == null) {
|
||||
executor.execute(() -> {
|
||||
@SuppressWarnings("unchecked")
|
||||
var holder = (Holder<T>) PENDING_ARG_HANDLE.getAndSet(this, (Holder<T>) null);
|
||||
|
||||
// If the executor supports multiple underlying threads,
|
||||
// we need to add synchronization, but for now we can omit it :)
|
||||
// synchronized (InvocationDispatcher.this)
|
||||
action.accept(holder.value);
|
||||
action.accept(pendingArg.getAndSet(null).value);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -30,7 +30,7 @@ import java.util.ResourceBundle;
|
||||
/// - For all Chinese locales, `zh-CN` is always added to the candidate list. If `zh-Hans` already exists in the candidate list,
|
||||
/// `zh-CN` is inserted before `zh`; otherwise, it is inserted after `zh`.
|
||||
/// - For all Traditional Chinese locales, `zh-TW` is always added to the candidate list (before `zh`).
|
||||
/// - For all supported ISO 639-3 language code (such as `eng`, `zho`, `lzh`, etc.),
|
||||
/// - For all [supported][LocaleUtils#mapToISO2Language(String)] ISO 639-3 language code (such as `eng`, `zho`, `lzh`, etc.),
|
||||
/// a candidate list with the language code replaced by the ISO 639-1 (Macro)language code is added to the end of the candidate list.
|
||||
///
|
||||
/// @author Glavo
|
||||
|
||||
@@ -17,7 +17,9 @@
|
||||
*/
|
||||
package org.jackhuang.hmcl.util.i18n;
|
||||
|
||||
import org.jackhuang.hmcl.util.Lang;
|
||||
import org.jackhuang.hmcl.util.StringUtils;
|
||||
import org.jackhuang.hmcl.util.io.IOUtils;
|
||||
import org.jackhuang.hmcl.util.platform.NativeUtils;
|
||||
import org.jackhuang.hmcl.util.platform.OperatingSystem;
|
||||
import org.jackhuang.hmcl.util.platform.windows.Kernel32;
|
||||
@@ -27,8 +29,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.Unmodifiable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.time.Duration;
|
||||
@@ -48,74 +48,66 @@ public final class LocaleUtils {
|
||||
|
||||
public static final Locale SYSTEM_DEFAULT = Locale.getDefault();
|
||||
|
||||
public static final boolean IS_CHINA_MAINLAND = isChinaMainland();
|
||||
|
||||
private static boolean isChinaMainland() {
|
||||
if ("Asia/Shanghai".equals(ZoneId.systemDefault().getId()))
|
||||
return true;
|
||||
|
||||
// Check if the time zone is UTC+8
|
||||
if (ZonedDateTime.now().getOffset().getTotalSeconds() == Duration.ofHours(8).toSeconds()) {
|
||||
if ("CN".equals(LocaleUtils.SYSTEM_DEFAULT.getCountry()))
|
||||
return true;
|
||||
|
||||
if (OperatingSystem.CURRENT_OS == OperatingSystem.WINDOWS && NativeUtils.USE_JNA) {
|
||||
Kernel32 kernel32 = Kernel32.INSTANCE;
|
||||
|
||||
// https://learn.microsoft.com/windows/win32/intl/table-of-geographical-locations
|
||||
if (kernel32 != null && kernel32.GetUserGeoID(WinConstants.GEOCLASS_NATION) == 45) // China
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static final Locale LOCALE_ZH_HANS = Locale.forLanguageTag("zh-Hans");
|
||||
public static final Locale LOCALE_ZH_HANT = Locale.forLanguageTag("zh-Hant");
|
||||
|
||||
public static final String DEFAULT_LANGUAGE_KEY = "default";
|
||||
|
||||
private static final Map<String, String> PARENT_LANGUAGE = loadCSV("sublanguages.csv");
|
||||
private static final Map<String, String> NORMALIZED_TAG = loadCSV("language_aliases.csv");
|
||||
private static final Map<String, String> DEFAULT_SCRIPT = loadCSV("default_script.csv");
|
||||
private static final Map<String, String> PREFERRED_LANGUAGE = Map.of("zh", "cmn");
|
||||
private static final Set<String> RTL_SCRIPTS = Set.of("Qabs", "Arab", "Hebr");
|
||||
private static final Set<String> CHINESE_TRADITIONAL_REGIONS = Set.of("TW", "HK", "MO");
|
||||
private static final Map<String, String> subLanguageToParent = new HashMap<>();
|
||||
private static final Map<String, String> iso3To2 = new HashMap<>();
|
||||
private static final Set<String> rtl = new HashSet<>();
|
||||
|
||||
/// Load CSV files located in `/assets/lang/`.
|
||||
/// Each line in these files contains at least two elements.
|
||||
///
|
||||
/// For example, if a file contains `value0,value1,value2`, the return value will be `{value1=value0, value2=value0}`.
|
||||
private static Map<String, String> loadCSV(String fileName) {
|
||||
InputStream resource = LocaleUtils.class.getResourceAsStream("/assets/lang/" + fileName);
|
||||
if (resource == null) {
|
||||
LOG.warning("Can't find file: " + fileName);
|
||||
return Map.of();
|
||||
}
|
||||
|
||||
HashMap<String, String> result = new HashMap<>();
|
||||
try (resource) {
|
||||
new String(resource.readAllBytes(), StandardCharsets.UTF_8).lines().forEach(line -> {
|
||||
if (line.startsWith("#") || line.isBlank())
|
||||
return;
|
||||
|
||||
String[] items = line.split(",");
|
||||
if (items.length < 2) {
|
||||
LOG.warning("Invalid line in " + fileName + ": " + line);
|
||||
return;
|
||||
static {
|
||||
try {
|
||||
for (String line : Lang.toIterable(IOUtils.readFullyAsString(LocaleUtils.class.getResourceAsStream("/assets/lang/sublanguages.csv")).lines())) {
|
||||
if (line.startsWith("#") || line.isBlank()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String parent = items[0];
|
||||
for (int i = 1; i < items.length; i++) {
|
||||
result.put(items[i], parent);
|
||||
String[] languages = line.split(",");
|
||||
if (languages.length < 2) {
|
||||
LOG.warning("Invalid line in sublanguages.csv: " + line);
|
||||
continue;
|
||||
}
|
||||
});
|
||||
|
||||
String parent = languages[0];
|
||||
for (int i = 1; i < languages.length; i++) {
|
||||
subLanguageToParent.put(languages[i], parent);
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
LOG.warning("Failed to load " + fileName, e);
|
||||
LOG.warning("Failed to load sublanguages.csv", e);
|
||||
}
|
||||
|
||||
return Map.copyOf(result);
|
||||
try {
|
||||
// Line Format: (?<iso2>[a-z]{2}),(?<iso3>[a-z]{3})
|
||||
for (String line : Lang.toIterable(IOUtils.readFullyAsString(LocaleUtils.class.getResourceAsStream("/assets/lang/iso_languages.csv")).lines())) {
|
||||
if (line.startsWith("#") || line.isBlank()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String[] parts = line.split(",", 3);
|
||||
if (parts.length != 2) {
|
||||
LOG.warning("Invalid line in iso_languages.csv: " + line);
|
||||
continue;
|
||||
}
|
||||
|
||||
iso3To2.put(parts[1], parts[0]);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
LOG.warning("Failed to load iso_languages.csv", e);
|
||||
}
|
||||
|
||||
try {
|
||||
for (String line : Lang.toIterable(IOUtils.readFullyAsString(LocaleUtils.class.getResourceAsStream("/assets/lang/rtl.txt")).lines())) {
|
||||
if (line.startsWith("#") || line.isBlank()) {
|
||||
continue;
|
||||
}
|
||||
rtl.add(line.trim());
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
LOG.warning("Failed to load rtl.txt", e);
|
||||
}
|
||||
}
|
||||
|
||||
private static Locale getInstance(String language, String script, String region,
|
||||
@@ -138,31 +130,6 @@ public final class LocaleUtils {
|
||||
: locale.stripExtensions().toLanguageTag();
|
||||
}
|
||||
|
||||
public static boolean isEnglish(Locale locale) {
|
||||
return "en".equals(getRootLanguage(locale));
|
||||
}
|
||||
|
||||
public static boolean isChinese(Locale locale) {
|
||||
return "zh".equals(getRootLanguage(locale));
|
||||
}
|
||||
|
||||
// ---
|
||||
|
||||
/// Normalize the language code to the code in the IANA Language Subtag Registry.
|
||||
/// 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"
|
||||
: NORMALIZED_TAG.getOrDefault(language, language);
|
||||
}
|
||||
|
||||
/// If `language` is a sublanguage of a [macrolanguage](https://en.wikipedia.org/wiki/ISO_639_macrolanguage),
|
||||
/// return the macrolanguage; otherwise, return `null`.
|
||||
public static @Nullable String getParentLanguage(String language) {
|
||||
return PARENT_LANGUAGE.get(language);
|
||||
}
|
||||
|
||||
/// @see #getRootLanguage(String)
|
||||
public static @NotNull String getRootLanguage(Locale locale) {
|
||||
return getRootLanguage(locale.getLanguage());
|
||||
}
|
||||
@@ -173,54 +140,54 @@ public final class LocaleUtils {
|
||||
/// - If `language` is empty, return `en`;
|
||||
/// - Otherwise, return the `language`.
|
||||
public static @NotNull String getRootLanguage(String language) {
|
||||
language = normalizeLanguage(language);
|
||||
if (language.isEmpty()) return "en";
|
||||
if (language.length() <= 2)
|
||||
return language;
|
||||
|
||||
String iso2 = mapToISO2Language(language);
|
||||
if (iso2 != null)
|
||||
return iso2;
|
||||
|
||||
String parent = getParentLanguage(language);
|
||||
return parent != null ? parent : language;
|
||||
}
|
||||
|
||||
/// If `language` is a macrolanguage, try to map it to the most commonly used individual language.
|
||||
///
|
||||
/// For example, if `language` is `zh`, this method will return `cmn`.
|
||||
public static @NotNull String getPreferredLanguage(String language) {
|
||||
language = normalizeLanguage(language);
|
||||
return PREFERRED_LANGUAGE.getOrDefault(language, language);
|
||||
}
|
||||
|
||||
/// Get the script of the locale. If the script is empty and the language is Chinese,
|
||||
/// the script will be inferred based on the language, the region and the variant.
|
||||
public static @NotNull String getScript(Locale locale) {
|
||||
if (locale.getScript().isEmpty()) {
|
||||
if (!locale.getVariant().isEmpty()) {
|
||||
String script = DEFAULT_SCRIPT.get(locale.getVariant());
|
||||
if (script != null)
|
||||
return script;
|
||||
if (isEnglish(locale)) {
|
||||
if ("UD".equals(locale.getCountry())) {
|
||||
return "Qabs";
|
||||
}
|
||||
}
|
||||
|
||||
if ("UD".equals(locale.getCountry())) {
|
||||
return "Qabs";
|
||||
}
|
||||
|
||||
String script = DEFAULT_SCRIPT.get(normalizeLanguage(locale.getLanguage()));
|
||||
if (script != null)
|
||||
return script;
|
||||
|
||||
if (isChinese(locale)) {
|
||||
return CHINESE_TRADITIONAL_REGIONS.contains(locale.getCountry())
|
||||
? "Hant"
|
||||
: "Hans";
|
||||
if (CHINESE_LATN_VARIANTS.contains(locale.getVariant()))
|
||||
return "Latn";
|
||||
if (locale.getLanguage().equals("lzh") || CHINESE_TRADITIONAL_REGIONS.contains(locale.getCountry()))
|
||||
return "Hant";
|
||||
else
|
||||
return "Hans";
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
return locale.getScript();
|
||||
}
|
||||
|
||||
public static @NotNull TextDirection getTextDirection(Locale locale) {
|
||||
return RTL_SCRIPTS.contains(getScript(locale))
|
||||
TextDirection direction = rtl.contains(getRootLanguage(locale))
|
||||
? TextDirection.RIGHT_TO_LEFT
|
||||
: TextDirection.LEFT_TO_RIGHT;
|
||||
|
||||
if ("Qabs".equals(getScript(locale))) {
|
||||
direction = switch (direction) {
|
||||
case RIGHT_TO_LEFT -> TextDirection.LEFT_TO_RIGHT;
|
||||
case LEFT_TO_RIGHT -> TextDirection.RIGHT_TO_LEFT;
|
||||
};
|
||||
}
|
||||
|
||||
return direction;
|
||||
}
|
||||
|
||||
private static final ConcurrentMap<Locale, List<Locale>> CANDIDATE_LOCALES = new ConcurrentHashMap<>();
|
||||
@@ -229,8 +196,13 @@ public final class LocaleUtils {
|
||||
return CANDIDATE_LOCALES.computeIfAbsent(locale, LocaleUtils::createCandidateLocaleList);
|
||||
}
|
||||
|
||||
// -------------
|
||||
|
||||
private static List<Locale> createCandidateLocaleList(Locale locale) {
|
||||
String language = getPreferredLanguage(locale.getLanguage());
|
||||
String language = locale.getLanguage();
|
||||
if (language.isEmpty())
|
||||
return List.of(Locale.ENGLISH, Locale.ROOT);
|
||||
|
||||
String script = getScript(locale);
|
||||
String region = locale.getCountry();
|
||||
List<String> variants = locale.getVariant().isEmpty()
|
||||
@@ -239,7 +211,18 @@ public final class LocaleUtils {
|
||||
|
||||
ArrayList<Locale> result = new ArrayList<>();
|
||||
do {
|
||||
addCandidateLocales(result, language, script, region, variants);
|
||||
String currentLanguage;
|
||||
|
||||
if (language.length() <= 2) {
|
||||
currentLanguage = language;
|
||||
} else {
|
||||
String iso2 = mapToISO2Language(language);
|
||||
currentLanguage = iso2 != null
|
||||
? iso2
|
||||
: language;
|
||||
}
|
||||
|
||||
addCandidateLocales(result, currentLanguage, script, region, variants);
|
||||
} while ((language = getParentLanguage(language)) != null);
|
||||
|
||||
result.add(Locale.ROOT);
|
||||
@@ -384,6 +367,54 @@ public final class LocaleUtils {
|
||||
return Map.of();
|
||||
}
|
||||
|
||||
// ---
|
||||
|
||||
/// Map ISO 639 alpha-3 language codes to ISO 639 alpha-2 language codes.
|
||||
/// Returns `null` if there is no corresponding ISO 639 alpha-2 language code.
|
||||
public static @Nullable String mapToISO2Language(String iso3Language) {
|
||||
return iso3To2.get(iso3Language);
|
||||
}
|
||||
|
||||
/// If `language` is a sublanguage of a [macrolanguage](https://en.wikipedia.org/wiki/ISO_639_macrolanguage),
|
||||
/// return the macrolanguage; otherwise, return `null`.
|
||||
public static @Nullable String getParentLanguage(String language) {
|
||||
return subLanguageToParent.get(language);
|
||||
}
|
||||
|
||||
public static boolean isEnglish(Locale locale) {
|
||||
return "en".equals(getRootLanguage(locale));
|
||||
}
|
||||
|
||||
public static final Set<String> CHINESE_TRADITIONAL_REGIONS = Set.of("TW", "HK", "MO");
|
||||
public static final Set<String> CHINESE_LATN_VARIANTS = Set.of("pinyin", "wadegile", "tongyong");
|
||||
|
||||
public static boolean isChinese(Locale locale) {
|
||||
return "zh".equals(getRootLanguage(locale));
|
||||
}
|
||||
|
||||
public static final boolean IS_CHINA_MAINLAND = isChinaMainland();
|
||||
|
||||
private static boolean isChinaMainland() {
|
||||
if ("Asia/Shanghai".equals(ZoneId.systemDefault().getId()))
|
||||
return true;
|
||||
|
||||
// Check if the time zone is UTC+8
|
||||
if (ZonedDateTime.now().getOffset().getTotalSeconds() == Duration.ofHours(8).toSeconds()) {
|
||||
if ("CN".equals(LocaleUtils.SYSTEM_DEFAULT.getCountry()))
|
||||
return true;
|
||||
|
||||
if (OperatingSystem.CURRENT_OS == OperatingSystem.WINDOWS && NativeUtils.USE_JNA) {
|
||||
Kernel32 kernel32 = Kernel32.INSTANCE;
|
||||
|
||||
// https://learn.microsoft.com/windows/win32/intl/table-of-geographical-locations
|
||||
if (kernel32 != null && kernel32.GetUserGeoID(WinConstants.GEOCLASS_NATION) == 45) // China
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private LocaleUtils() {
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
Arab,ar,fa,ps,ur
|
||||
Armn,hy
|
||||
Beng,as,bn
|
||||
Blis,zbl
|
||||
Cyrl,ab,be,bg,kk,mk,ru,uk
|
||||
Deva,hi,mr,ne,kok,mai
|
||||
Ethi,am,ti
|
||||
Geor,ka
|
||||
Grek,el
|
||||
Gujr,gu
|
||||
Guru,pa
|
||||
Hant,lzh
|
||||
Hebr,he,yi
|
||||
Jpan,ja
|
||||
Khmr,km
|
||||
Knda,kn
|
||||
Kore,ko
|
||||
Laoo,lo
|
||||
Latn,af,ay,bs,ca,ch,cs,cy,da,de,en,eo,es,et,eu,fi,fj,fo,fr,fy,ga,gl,gn,gv,hr,ht,hu,id,is,it,kl,la,lb,ln,lt,lv,mg,mh,ms,mt,na,nb,nd,nl,nn,no,nr,ny,om,pl,pt,qu,rm,rn,ro,rw,sg,sk,sl,sm,so,sq,ss,st,sv,sw,tl,tn,to,tr,ts,ve,vi,xh,zu,dsb,frr,frs,gsw,hsb,men,nds,niu,nso,tem,tkl,tmh,tpi,tvl,tailo,pinyin,hepburn,pehoeji,tongyong,wadegile
|
||||
Mlym,ml
|
||||
Mymr,my
|
||||
Nkoo,nqo
|
||||
Orya,or
|
||||
Sinh,si
|
||||
Taml,ta
|
||||
Telu,te
|
||||
Thaa,dv
|
||||
Thai,th
|
||||
Tibt,dz
|
||||
|
+1
@@ -73,6 +73,7 @@ io,ido
|
||||
is,isl
|
||||
it,ita
|
||||
iu,iku
|
||||
iw,heb
|
||||
ja,jpn
|
||||
ji,yid
|
||||
jv,jav
|
||||
|
@@ -0,0 +1,6 @@
|
||||
ar
|
||||
fa
|
||||
he
|
||||
ps
|
||||
ur
|
||||
yi
|
||||
@@ -1,63 +1 @@
|
||||
ak,tw,fat
|
||||
ar,aao,abh,abv,acm,acq,acw,acx,acy,adf,aeb,aec,afb,apc,apd,arb,arq,ars,ary,arz,auz,avl,ayh,ayl,ayn,ayp,pga,shu,ssh
|
||||
ay,ayc,ayr
|
||||
az,azb,azj
|
||||
cr,crj,crk,crl,crm,csw,cwd
|
||||
et,ekk,vro
|
||||
fa,pes,prs
|
||||
ff,ffm,fub,fuc,fue,fuf,fuh,fui,fuq,fuv
|
||||
gn,gnw,gug,gui,gun,nhd
|
||||
ik,esi,esk
|
||||
iu,ike,ikt
|
||||
kg,kng,kwy,ldi
|
||||
kr,kby,knc,krt
|
||||
ku,ckb,kmr,sdh
|
||||
kv,koi,kpv
|
||||
lv,ltg,lvs
|
||||
mg,bhr,bmm,bzc,msh,plt,skg,tdx,tkg,txy,xmv,xmw
|
||||
mn,khk,mvf
|
||||
ms,id,bjn,btj,bve,bvu,coa,dup,hji,jak,jax,kvb,kvr,kxd,lce,lcf,liw,max,meo,mfa,mfb,min,mqg,msi,mui,orn,ors,pel,pse,tmw,urk,vkk,vkt,xmm,zlm,zmi,zsm
|
||||
ne,dty,npi
|
||||
no,nb,nn
|
||||
oj,ciw,ojb,ojc,ojg,ojs,ojw,otw
|
||||
om,gax,gaz,hae,orc
|
||||
or,ory,spv
|
||||
ps,pbt,pbu,pst
|
||||
qu,qub,qud,quf,qug,quh,quk,qul,qup,qur,qus,quw,qux,quy,quz,qva,qvc,qve,qvh,qvi,qvj,qvl,qvm,qvn,qvo,qvp,qvs,qvw,qvz,qwa,qwc,qwh,qws,qxa,qxc,qxh,qxl,qxn,qxo,qxp,qxr,qxt,qxu,qxw
|
||||
sa,cls,vsn
|
||||
sc,sdc,sdn,src,sro
|
||||
sh,bs,hr,sr,cnr
|
||||
sq,aae,aat,aln,als
|
||||
sw,swc,swh
|
||||
uz,uzn,uzs
|
||||
yi,ydd,yih
|
||||
za,zch,zeh,zgb,zgm,zgn,zhd,zhn,zlj,zln,zlq,zqe,zyb,zyg,zyj,zyn,zzj
|
||||
zh,cdo,cjy,cmn,cnp,cpx,csp,czh,czo,gan,hak,hnm,hsn,luh,lzh,mnp,nan,sjc,wuu,yue
|
||||
bal,bcc,bgn,bgp
|
||||
bik,bcl,bln,bto,cts,fbl,lbl,rbl,ubl
|
||||
bnc,ebk,lbk,obk,rbk,vbk
|
||||
bua,bxm,bxr,bxu
|
||||
chm,mhr,mrj
|
||||
del,umu,unm
|
||||
den,scs,xsl
|
||||
din,dib,dik,dip,diw,dks
|
||||
doi,dgo,xnr
|
||||
gba,bdt,gbp,gbq,gmm,gso,gya
|
||||
gon,esg,gno,wsg
|
||||
grb,gbo,gec,grj,grv,gry
|
||||
hai,hax,hdn
|
||||
hmn,cqd,hea,hma,hmc,hmd,hme,hmg,hmh,hmi,hmj,hml,hmm,hmp,hmq,hms,hmw,hmy,hmz,hnj,hrm,huj,mmr,muq,mww,sfm
|
||||
jrb,aju,jye,yhd,yud
|
||||
kln,enb,eyo,niq,oki,pko,sgc,spy,tec,tuy
|
||||
kok,gom,knn
|
||||
kpe,gkp,xpe
|
||||
lah,hnd,hno,jat,phr,pnb,skr,xhe
|
||||
luy,bxk,ida,lkb,lko,lks,lri,lrm,lsm,lto,lts,lwg,nle,nyd,rag
|
||||
man,emk,mku,mlq,mnk,msc,mwk
|
||||
mwr,dhd,mtr,mve,rwr,swv,wry
|
||||
raj,bgq,gda,gju,hoj,mup,wbr
|
||||
rom,rmc,rmf,rml,rmn,rmo,rmw,rmy
|
||||
syr,aii,cld
|
||||
tmh,taq,thv,thz,ttq
|
||||
zap,zaa,zab,zac,zad,zae,zaf,zai,zam,zao,zaq,zar,zas,zat,zav,zaw,zax,zca,zcd,zoo,zpa,zpb,zpc,zpd,zpe,zpf,zpg,zph,zpi,zpj,zpk,zpl,zpm,zpn,zpo,zpp,zpq,zpr,zps,zpt,zpu,zpv,zpw,zpx,zpy,zpz,zsr,zte,ztg,ztl,ztm,ztn,ztp,ztq,zts,ztt,ztu,ztx,zty
|
||||
zza,diq,kiu
|
||||
zh,cdo,cjy,cmn,cnp,cpx,csp,czh,czo,gan,hak,hnm,hsn,luh,lzh,mnp,nan,sjc,wuu,yue
|
||||
|
@@ -28,6 +28,7 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@@ -40,76 +41,55 @@ public final class LocaleUtilsTest {
|
||||
LocaleUtils.getCandidateLocales(Locale.forLanguageTag(languageTag))
|
||||
.stream()
|
||||
.map(Locale::toLanguageTag)
|
||||
.toList());
|
||||
}
|
||||
|
||||
private static void assertCandidateLocalesEquals(String l1, String l2) {
|
||||
assertEquals(
|
||||
LocaleUtils.getCandidateLocales(Locale.forLanguageTag(l1)),
|
||||
LocaleUtils.getCandidateLocales(Locale.forLanguageTag(l2))
|
||||
);
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetCandidateLocales() {
|
||||
// English
|
||||
|
||||
assertCandidateLocales("en", List.of("en-Latn", "en", "und"));
|
||||
assertCandidateLocales("en-US", List.of("en-Latn-US", "en-Latn", "en-US", "en", "und"));
|
||||
assertCandidateLocalesEquals("en", "eng");
|
||||
assertCandidateLocalesEquals("en-US", "eng-US");
|
||||
assertCandidateLocalesEquals("und", "en");
|
||||
|
||||
// Spanish
|
||||
|
||||
assertCandidateLocales("es", List.of("es-Latn", "es", "und"));
|
||||
assertCandidateLocalesEquals("es", "spa");
|
||||
|
||||
// Japanese
|
||||
|
||||
assertCandidateLocales("ja", List.of("ja-Jpan", "ja", "und"));
|
||||
assertCandidateLocales("ja-JP", List.of("ja-Jpan-JP", "ja-Jpan", "ja-JP", "ja", "und"));
|
||||
assertCandidateLocalesEquals("ja", "jpn");
|
||||
assertCandidateLocalesEquals("ja-JP", "jpn-JP");
|
||||
|
||||
// Russian
|
||||
|
||||
assertCandidateLocales("ru", List.of("ru-Cyrl", "ru", "und"));
|
||||
assertCandidateLocalesEquals("ru", "rus");
|
||||
|
||||
// Ukrainian
|
||||
|
||||
assertCandidateLocales("uk", List.of("uk-Cyrl", "uk", "und"));
|
||||
assertCandidateLocalesEquals("uk", "ukr");
|
||||
|
||||
// Chinese
|
||||
|
||||
assertCandidateLocales("zh", List.of("cmn-Hans", "cmn", "zh-Hans", "zh-CN", "zh", "und"));
|
||||
assertCandidateLocales("zh-CN", List.of("cmn-Hans-CN", "cmn-Hans", "cmn-CN", "cmn", "zh-Hans-CN", "zh-Hans", "zh-CN", "zh", "und"));
|
||||
assertCandidateLocales("zh-SG", List.of("cmn-Hans-SG", "cmn-Hans", "cmn-SG", "cmn", "zh-Hans-SG", "zh-Hans", "zh-SG", "zh-CN", "zh", "und"));
|
||||
|
||||
assertCandidateLocales("zh-TW", List.of("cmn-Hant-TW", "cmn-Hant", "cmn-TW", "cmn", "zh-Hant-TW", "zh-Hant", "zh-TW", "zh", "zh-CN", "und"));
|
||||
assertCandidateLocales("zh-HK", List.of("cmn-Hant-HK", "cmn-Hant", "cmn-HK", "cmn", "zh-Hant-HK", "zh-Hant", "zh-HK", "zh-TW", "zh", "zh-CN", "und"));
|
||||
assertCandidateLocales("zh-Hant-CN", List.of("cmn-Hant-CN", "cmn-Hant", "cmn-CN", "cmn", "zh-Hant-CN", "zh-Hant", "zh-CN", "zh-TW", "zh", "und"));
|
||||
|
||||
assertCandidateLocales("zh-pinyin", List.of("cmn-Latn-pinyin", "cmn-Latn", "cmn-pinyin", "cmn", "zh-Latn-pinyin", "zh-Latn", "zh-pinyin", "zh", "zh-CN", "und"));
|
||||
|
||||
assertCandidateLocales("zh", List.of("zh-Hans", "zh-CN", "zh", "und"));
|
||||
assertCandidateLocales("zh-CN", List.of("zh-Hans-CN", "zh-Hans", "zh-CN", "zh", "und"));
|
||||
assertCandidateLocales("zh-SG", List.of("zh-Hans-SG", "zh-Hans", "zh-SG", "zh-CN", "zh", "und"));
|
||||
assertCandidateLocales("zh-MY", List.of("zh-Hans-MY", "zh-Hans", "zh-MY", "zh-CN", "zh", "und"));
|
||||
assertCandidateLocales("zh-US", List.of("zh-Hans-US", "zh-Hans", "zh-US", "zh-CN", "zh", "und"));
|
||||
assertCandidateLocales("zh-TW", List.of("zh-Hant-TW", "zh-Hant", "zh-TW", "zh", "zh-CN", "und"));
|
||||
assertCandidateLocales("zh-HK", List.of("zh-Hant-HK", "zh-Hant", "zh-HK", "zh-TW", "zh", "zh-CN", "und"));
|
||||
assertCandidateLocales("zh-MO", List.of("zh-Hant-MO", "zh-Hant", "zh-MO", "zh-TW", "zh", "zh-CN", "und"));
|
||||
assertCandidateLocales("zh-Hans", List.of("zh-Hans", "zh-CN", "zh", "und"));
|
||||
assertCandidateLocales("zh-Hant", List.of("zh-Hant", "zh-TW", "zh", "zh-CN", "und"));
|
||||
assertCandidateLocales("zh-Hans-US", List.of("zh-Hans-US", "zh-Hans", "zh-US", "zh-CN", "zh", "und"));
|
||||
assertCandidateLocales("zh-Hant-CN", List.of("zh-Hant-CN", "zh-Hant", "zh-CN", "zh-TW", "zh", "und"));
|
||||
assertCandidateLocales("zh-Hans-TW", List.of("zh-Hans-TW", "zh-Hans", "zh-TW", "zh-CN", "zh", "und"));
|
||||
assertCandidateLocales("zh-Latn", List.of("zh-Latn", "zh", "zh-CN", "und"));
|
||||
assertCandidateLocales("zh-Latn-CN", List.of("zh-Latn-CN", "zh-Latn", "zh-CN", "zh", "und"));
|
||||
assertCandidateLocales("zh-pinyin", List.of("zh-Latn-pinyin", "zh-Latn", "zh-pinyin", "zh", "zh-CN", "und"));
|
||||
assertCandidateLocales("zho", List.of("zh-Hans", "zh-CN", "zh", "und"));
|
||||
assertCandidateLocales("lzh", List.of("lzh-Hant", "lzh", "zh-Hant", "zh-TW", "zh", "zh-CN", "und"));
|
||||
assertCandidateLocales("lzh-Hant", List.of("lzh-Hant", "lzh", "zh-Hant", "zh-TW", "zh", "zh-CN", "und"));
|
||||
assertCandidateLocales("lzh-Hans", List.of("lzh-Hans", "lzh", "zh-Hans", "zh-CN", "zh", "und"));
|
||||
assertCandidateLocales("cmn", List.of("cmn-Hans", "cmn", "zh-Hans", "zh-CN", "zh", "und"));
|
||||
assertCandidateLocales("cmn-Hans", List.of("cmn-Hans", "cmn", "zh-Hans", "zh-CN", "zh", "und"));
|
||||
assertCandidateLocales("yue", List.of("yue-Hans", "yue", "zh-Hans", "zh-CN", "zh", "und"));
|
||||
|
||||
assertCandidateLocalesEquals("zh", "cmn-Hans");
|
||||
assertCandidateLocalesEquals("zh-CN", "cmn-Hans-CN");
|
||||
assertCandidateLocalesEquals("zh-SG", "cmn-Hans-SG");
|
||||
assertCandidateLocalesEquals("zh-MY", "cmn-Hans-MY");
|
||||
assertCandidateLocalesEquals("zh-TW", "cmn-Hant-TW");
|
||||
assertCandidateLocalesEquals("zh-HK", "cmn-Hant-HK");
|
||||
assertCandidateLocalesEquals("zh-Hans", "cmn-Hans");
|
||||
assertCandidateLocalesEquals("zh-Hant", "cmn-Hant");
|
||||
assertCandidateLocalesEquals("zh-Hant-CN", "cmn-Hant-CN");
|
||||
assertCandidateLocalesEquals("zh-Hant-SG", "cmn-Hant-SG");
|
||||
assertCandidateLocalesEquals("zh-Latn", "cmn-Latn");
|
||||
assertCandidateLocalesEquals("zh-pinyin", "cmn-Latn-pinyin");
|
||||
assertCandidateLocalesEquals("zho", "zh");
|
||||
assertCandidateLocales("ja", List.of("ja", "und"));
|
||||
assertCandidateLocales("jpn", List.of("ja", "und"));
|
||||
assertCandidateLocales("ja-JP", List.of("ja-JP", "ja", "und"));
|
||||
assertCandidateLocales("jpn-JP", List.of("ja-JP", "ja", "und"));
|
||||
|
||||
assertCandidateLocales("en", List.of("en", "und"));
|
||||
assertCandidateLocales("eng", List.of("en", "und"));
|
||||
assertCandidateLocales("en-US", List.of("en-US", "en", "und"));
|
||||
assertCandidateLocales("eng-US", List.of("en-US", "en", "und"));
|
||||
|
||||
assertCandidateLocales("es", List.of("es", "und"));
|
||||
assertCandidateLocales("spa", List.of("es", "und"));
|
||||
|
||||
assertCandidateLocales("ru", List.of("ru", "und"));
|
||||
assertCandidateLocales("rus", List.of("ru", "und"));
|
||||
|
||||
assertCandidateLocales("uk", List.of("uk", "und"));
|
||||
assertCandidateLocales("ukr", List.of("uk", "und"));
|
||||
|
||||
assertCandidateLocales("und", List.of("en", "und"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -154,9 +134,7 @@ public final class LocaleUtilsTest {
|
||||
assertEquals("Hant", LocaleUtils.getScript(Locale.forLanguageTag("lzh-Hant")));
|
||||
assertEquals("Hant", LocaleUtils.getScript(Locale.forLanguageTag("lzh-CN")));
|
||||
|
||||
assertEquals("Latn", LocaleUtils.getScript(Locale.forLanguageTag("en")));
|
||||
assertEquals("Latn", LocaleUtils.getScript(Locale.forLanguageTag("zh-pinyin")));
|
||||
assertEquals("Latn", LocaleUtils.getScript(Locale.forLanguageTag("ja-hepburn")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -214,17 +192,20 @@ public final class LocaleUtilsTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNormalizeLanguage() {
|
||||
assertEquals("en", LocaleUtils.normalizeLanguage(""));
|
||||
assertEquals("en", LocaleUtils.normalizeLanguage("eng"));
|
||||
assertEquals("es", LocaleUtils.normalizeLanguage("spa"));
|
||||
assertEquals("ja", LocaleUtils.normalizeLanguage("jpn"));
|
||||
assertEquals("ru", LocaleUtils.normalizeLanguage("rus"));
|
||||
assertEquals("uk", LocaleUtils.normalizeLanguage("ukr"));
|
||||
assertEquals("zh", LocaleUtils.normalizeLanguage("zho"));
|
||||
assertEquals("zu", LocaleUtils.normalizeLanguage("zul"));
|
||||
assertEquals("en", LocaleUtils.normalizeLanguage(""));
|
||||
assertEquals("cmn", LocaleUtils.normalizeLanguage("cmn"));
|
||||
public void testMapToISO2Language() {
|
||||
assertEquals("en", LocaleUtils.mapToISO2Language("eng"));
|
||||
assertEquals("es", LocaleUtils.mapToISO2Language("spa"));
|
||||
assertEquals("ja", LocaleUtils.mapToISO2Language("jpn"));
|
||||
assertEquals("ru", LocaleUtils.mapToISO2Language("rus"));
|
||||
assertEquals("uk", LocaleUtils.mapToISO2Language("ukr"));
|
||||
assertEquals("zh", LocaleUtils.mapToISO2Language("zho"));
|
||||
assertEquals("zu", LocaleUtils.mapToISO2Language("zul"));
|
||||
|
||||
assertNull(LocaleUtils.mapToISO2Language(null));
|
||||
assertNull(LocaleUtils.mapToISO2Language(""));
|
||||
assertNull(LocaleUtils.mapToISO2Language("cmn"));
|
||||
assertNull(LocaleUtils.mapToISO2Language("lzh"));
|
||||
assertNull(LocaleUtils.mapToISO2Language("tlh"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -247,11 +228,10 @@ public final class LocaleUtilsTest {
|
||||
assertEquals(TextDirection.LEFT_TO_RIGHT, LocaleUtils.getTextDirection(Locale.forLanguageTag("zh")));
|
||||
assertEquals(TextDirection.LEFT_TO_RIGHT, LocaleUtils.getTextDirection(Locale.forLanguageTag("zh-Hans")));
|
||||
assertEquals(TextDirection.LEFT_TO_RIGHT, LocaleUtils.getTextDirection(Locale.forLanguageTag("zh-CN")));
|
||||
assertEquals(TextDirection.LEFT_TO_RIGHT, LocaleUtils.getTextDirection(Locale.forLanguageTag("ar-Qabs")));
|
||||
|
||||
assertEquals(TextDirection.RIGHT_TO_LEFT, LocaleUtils.getTextDirection(Locale.forLanguageTag("en-Qabs")));
|
||||
assertEquals(TextDirection.RIGHT_TO_LEFT, LocaleUtils.getTextDirection(Locale.forLanguageTag("ar")));
|
||||
assertEquals(TextDirection.RIGHT_TO_LEFT, LocaleUtils.getTextDirection(Locale.forLanguageTag("ara")));
|
||||
assertEquals(TextDirection.RIGHT_TO_LEFT, LocaleUtils.getTextDirection(Locale.forLanguageTag("he")));
|
||||
assertEquals(TextDirection.RIGHT_TO_LEFT, LocaleUtils.getTextDirection(Locale.forLanguageTag("heb")));
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
import org.jackhuang.hmcl.gradle.ci.CheckUpdate
|
||||
import org.jackhuang.hmcl.gradle.docs.UpdateDocuments
|
||||
import org.jackhuang.hmcl.gradle.l10n.ParseLanguageSubtagRegistry
|
||||
|
||||
plugins {
|
||||
id("checkstyle")
|
||||
@@ -77,12 +76,6 @@ org.jackhuang.hmcl.gradle.javafx.JavaFXUtils.register(rootProject)
|
||||
|
||||
defaultTasks("clean", "build")
|
||||
|
||||
tasks.register<ParseLanguageSubtagRegistry>("parseLanguageSubtagRegistry") {
|
||||
languageSubtagRegistryFile.set(layout.projectDirectory.file("language-subtag-registry"))
|
||||
|
||||
sublanguagesFile.set(layout.projectDirectory.file("HMCLCore/src/main/resources/assets/lang/sublanguages.csv"))
|
||||
defaultScriptFile.set(layout.projectDirectory.file("HMCLCore/src/main/resources/assets/lang/default_script.csv"))
|
||||
}
|
||||
|
||||
tasks.register<UpdateDocuments>("updateDocuments") {
|
||||
documentsDir.set(layout.projectDirectory.dir("docs"))
|
||||
|
||||
@@ -103,8 +103,12 @@ public record Document(DocumentFileTree directory,
|
||||
|
||||
if (line == null)
|
||||
throw new IOException("Missing end line for macro: " + macroName);
|
||||
else if (line.equals(endLine)) {
|
||||
break;
|
||||
else if (line.startsWith("<!-- #END")) {
|
||||
if (line.equals(endLine)) {
|
||||
break;
|
||||
} else {
|
||||
throw new IOException("Invalid macro end line: " + line);
|
||||
}
|
||||
} else {
|
||||
lines.add(line);
|
||||
}
|
||||
|
||||
@@ -19,42 +19,36 @@ package org.jackhuang.hmcl.gradle.l10n;
|
||||
|
||||
import org.gradle.api.GradleException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
|
||||
final class LocalizationUtils {
|
||||
public static final Map<String, String> subLanguageToParent = loadCSV("sublanguages.csv");
|
||||
public static final Map<String, String> subLanguageToParent;
|
||||
|
||||
private static Map<String, String> loadCSV(String fileName) {
|
||||
InputStream resource = LocalizationUtils.class.getResourceAsStream(fileName);
|
||||
if (resource == null) {
|
||||
throw new GradleException("Resource not found: " + fileName);
|
||||
static {
|
||||
InputStream input = LocalizationUtils.class.getResourceAsStream("sublanguages.csv");
|
||||
if (input == null)
|
||||
throw new GradleException("Missing sublanguages.csv file");
|
||||
|
||||
Map<String, String> map = new HashMap<>();
|
||||
try (input) {
|
||||
new String(input.readAllBytes()).lines()
|
||||
.filter(line -> !line.startsWith("#") && !line.isBlank())
|
||||
.forEach(line -> {
|
||||
String[] languages = line.split(",");
|
||||
if (languages.length < 2)
|
||||
throw new GradleException("Invalid line in sublanguages.csv: " + line);
|
||||
|
||||
String parent = languages[0];
|
||||
for (int i = 1; i < languages.length; i++) {
|
||||
map.put(languages[i], parent);
|
||||
}
|
||||
});
|
||||
} catch (IOException e) {
|
||||
throw new GradleException("Failed to read sublanguages.csv", e);
|
||||
}
|
||||
|
||||
HashMap<String, String> result = new HashMap<>();
|
||||
try (resource) {
|
||||
new String(resource.readAllBytes(), StandardCharsets.UTF_8).lines().forEach(line -> {
|
||||
if (line.startsWith("#") || line.isBlank())
|
||||
return;
|
||||
|
||||
String[] items = line.split(",");
|
||||
if (items.length < 2) {
|
||||
throw new GradleException("Invalid line in sublanguages.csv: " + line);
|
||||
}
|
||||
|
||||
String parent = items[0];
|
||||
for (int i = 1; i < items.length; i++) {
|
||||
result.put(items[i], parent);
|
||||
}
|
||||
});
|
||||
} catch (RuntimeException | Error e) {
|
||||
throw e;
|
||||
} catch (Throwable e) {
|
||||
throw new GradleException("Failed to load " + fileName, e);
|
||||
}
|
||||
|
||||
return Map.copyOf(result);
|
||||
subLanguageToParent = Collections.unmodifiableMap(map);
|
||||
}
|
||||
|
||||
private static List<String> resolveLanguage(String language) {
|
||||
|
||||
-254
@@ -1,254 +0,0 @@
|
||||
/*
|
||||
* Hello Minecraft! Launcher
|
||||
* Copyright (C) 2025 huangyuhui <huanghongxun2008@126.com> and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.jackhuang.hmcl.gradle.l10n;
|
||||
|
||||
import org.gradle.api.DefaultTask;
|
||||
import org.gradle.api.GradleException;
|
||||
import org.gradle.api.file.RegularFileProperty;
|
||||
import org.gradle.api.tasks.InputFile;
|
||||
import org.gradle.api.tasks.OutputFile;
|
||||
import org.gradle.api.tasks.TaskAction;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/// @author Glavo
|
||||
/// @see [language-subtag-registry](https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry)
|
||||
public abstract class ParseLanguageSubtagRegistry extends DefaultTask {
|
||||
|
||||
@InputFile
|
||||
public abstract RegularFileProperty getLanguageSubtagRegistryFile();
|
||||
|
||||
@OutputFile
|
||||
public abstract RegularFileProperty getSublanguagesFile();
|
||||
|
||||
/// CSV file storing the mapping from subtag to their default scripts.
|
||||
@OutputFile
|
||||
public abstract RegularFileProperty getDefaultScriptFile();
|
||||
|
||||
@TaskAction
|
||||
public void run() throws IOException {
|
||||
List<Item> items;
|
||||
|
||||
try (var reader = Files.newBufferedReader(getLanguageSubtagRegistryFile().getAsFile().get().toPath())) {
|
||||
var builder = new ItemsBuilder();
|
||||
builder.parse(reader);
|
||||
items = builder.items;
|
||||
}
|
||||
|
||||
MultiMap scriptToSubtag = new MultiMap();
|
||||
MultiMap languageToSub = new MultiMap();
|
||||
|
||||
// Classical Chinese should use Traditional Chinese characters by default
|
||||
scriptToSubtag.add("Hant", "lzh");
|
||||
|
||||
for (Item item : items) {
|
||||
String type = item.firstValueOrThrow("Type");
|
||||
if (type.equals("grandfathered") || type.equals("redundant")
|
||||
|| !item.allValues("Deprecated").isEmpty())
|
||||
continue;
|
||||
|
||||
String subtag = item.firstValueOrThrow("Subtag");
|
||||
|
||||
mainSwitch:
|
||||
switch (type) {
|
||||
case "language", "extlang" -> {
|
||||
item.firstValue("Macrolanguage")
|
||||
.ifPresent(macroLang -> languageToSub.add(macroLang, subtag));
|
||||
|
||||
item.firstValue("Suppress-Script")
|
||||
.ifPresent(script -> scriptToSubtag.add(script, subtag));
|
||||
}
|
||||
case "variant" -> {
|
||||
List<String> prefixes = item.allValues("Prefix");
|
||||
String defaultScript = null;
|
||||
for (String prefix : prefixes) {
|
||||
String script = Locale.forLanguageTag(prefix).getScript();
|
||||
if (script.isEmpty()) {
|
||||
break mainSwitch;
|
||||
}
|
||||
|
||||
if (defaultScript == null) {
|
||||
defaultScript = script;
|
||||
} else {
|
||||
if (!defaultScript.equals(script)) {
|
||||
break mainSwitch;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (defaultScript != null) {
|
||||
scriptToSubtag.add(defaultScript, subtag);
|
||||
}
|
||||
}
|
||||
case "region", "script" -> {
|
||||
// ignored
|
||||
}
|
||||
default -> throw new GradleException(String.format("Unknown subtag type: %s", type));
|
||||
}
|
||||
}
|
||||
|
||||
languageToSub.saveToCSV(getSublanguagesFile());
|
||||
scriptToSubtag.saveToCSV(getDefaultScriptFile());
|
||||
}
|
||||
|
||||
private static final class MultiMap {
|
||||
private final TreeMap<String, Set<String>> allValues = new TreeMap<>(TAG_COMPARATOR);
|
||||
|
||||
void add(String key, String value) {
|
||||
allValues.computeIfAbsent(key, k -> new TreeSet<>(TAG_COMPARATOR)).add(value);
|
||||
}
|
||||
|
||||
void saveToCSV(RegularFileProperty csvFile) throws IOException {
|
||||
try (var writer = Files.newBufferedWriter(csvFile.getAsFile().get().toPath(),
|
||||
StandardOpenOption.CREATE,
|
||||
StandardOpenOption.TRUNCATE_EXISTING)) {
|
||||
|
||||
for (Map.Entry<String, Set<String>> entry : allValues.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
Set<String> values = entry.getValue();
|
||||
|
||||
writer.write(key);
|
||||
|
||||
for (String value : values) {
|
||||
writer.write(',');
|
||||
writer.write(value);
|
||||
}
|
||||
|
||||
writer.newLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static final class Item {
|
||||
final Map<String, List<String>> values = new LinkedHashMap<>();
|
||||
|
||||
public @NotNull List<String> allValues(String name) {
|
||||
return values.getOrDefault(name, List.of());
|
||||
}
|
||||
|
||||
public @NotNull Optional<String> firstValue(String name) {
|
||||
return Optional.ofNullable(values.get(name)).map(it -> it.get(0));
|
||||
}
|
||||
|
||||
public @Nullable String firstValueOrNull(String name) {
|
||||
return firstValue(name).orElse(null);
|
||||
}
|
||||
|
||||
public @NotNull String firstValueOrThrow(String name) {
|
||||
return firstValue(name).orElseThrow(() -> new GradleException("No value found for " + name + " in " + this));
|
||||
}
|
||||
|
||||
public void put(String name, String value) {
|
||||
values.computeIfAbsent(name, ignored -> new ArrayList<>(1)).add(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringJoiner joiner = new StringJoiner("\n");
|
||||
|
||||
values.forEach((name, values) -> {
|
||||
for (String value : values) {
|
||||
joiner.add(name + ": " + value);
|
||||
}
|
||||
});
|
||||
|
||||
return joiner.toString();
|
||||
}
|
||||
}
|
||||
|
||||
private static final class ItemsBuilder {
|
||||
private final List<Item> items = new ArrayList<>(1024);
|
||||
private Item current = new Item();
|
||||
private String currentName = null;
|
||||
private String currentValue = null;
|
||||
|
||||
private void updateCurrent() {
|
||||
if (currentName != null) {
|
||||
current.put(currentName, currentValue);
|
||||
currentName = null;
|
||||
currentValue = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void updateItems() throws IOException {
|
||||
updateCurrent();
|
||||
|
||||
if (current.values.isEmpty())
|
||||
return;
|
||||
|
||||
if (current.firstValue("Type").isEmpty()) {
|
||||
if (current.firstValue("File-Date").isPresent()) {
|
||||
current.values.clear();
|
||||
return;
|
||||
} else {
|
||||
throw new GradleException("Invalid item: " + current);
|
||||
}
|
||||
}
|
||||
|
||||
items.add(current);
|
||||
current = new Item();
|
||||
}
|
||||
|
||||
void parse(BufferedReader reader) throws IOException {
|
||||
Pattern linePattern = Pattern.compile("^(?<name>[A-Za-z\\-]+): (?<value>.*)$");
|
||||
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
if (line.isBlank()) {
|
||||
continue;
|
||||
} else if (line.equals("%%")) {
|
||||
updateItems();
|
||||
} else if (line.startsWith(" ")) {
|
||||
if (currentValue != null) {
|
||||
currentValue = currentValue + " " + line;
|
||||
} else {
|
||||
throw new GradleException("Invalid line: " + line);
|
||||
}
|
||||
} else {
|
||||
updateCurrent();
|
||||
|
||||
Matcher matcher = linePattern.matcher(line);
|
||||
if (matcher.matches()) {
|
||||
currentName = matcher.group("name");
|
||||
currentValue = matcher.group("value");
|
||||
} else {
|
||||
throw new GradleException("Invalid line: " + line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
updateItems();
|
||||
}
|
||||
}
|
||||
|
||||
private static final Comparator<String> TAG_COMPARATOR = (lang1, lang2) -> {
|
||||
if (lang1.length() != lang2.length())
|
||||
return Integer.compare(lang1.length(), lang2.length());
|
||||
else
|
||||
return lang1.compareTo(lang2);
|
||||
};
|
||||
}
|
||||
@@ -15,4 +15,4 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#
|
||||
versionRoot=3.8
|
||||
versionRoot=3.7
|
||||
@@ -1,337 +0,0 @@
|
||||
# Localization
|
||||
|
||||
<!-- #BEGIN LANGUAGE_SWITCHER -->
|
||||
**English** | [中文](Localization_zh.md)
|
||||
<!-- #END LANGUAGE_SWITCHER -->
|
||||
|
||||
HMCL provides localization support for multiple languages.
|
||||
|
||||
This document describes HMCL's support status for these languages and provides a guide for contributors who want to help with HMCL localization.
|
||||
|
||||
## Supported languages
|
||||
|
||||
Currently, HMCL supports the following languages:
|
||||
|
||||
| Language | Language Tag | Preferred Localization Key | Preferred Localization File Suffix | [Game Language Files](https://minecraft.wiki/w/Language) | Support Status | Volunteers |
|
||||
|-----------------------|--------------|----------------------------|------------------------------------|----------------------------------------------------------|----------------|-------------------------------------------|
|
||||
| English | `en` | `default` | (empty) | `en_us` | **Primary** | [Glavo](https://github.com/Glavo) |
|
||||
| English (Upside Down) | `en-Qabs` | `en-Qabs` | `en_Qabs` | `en_ud` | Automatic | |
|
||||
| Chinese (Simplified) | `zh-Hans` | `zh` | `_zh` | `zh_cn` | **Primary** | [Glavo](https://github.com/Glavo) |
|
||||
| Chinese (Traditional) | `zh-Hant` | `zh-Hant` | `_zh_Hant` | `zh_tw` <br/> `zh_hk` | **Primary** | [Glavo](https://github.com/Glavo) |
|
||||
| Chinese (Classical) | `lzh` | `lzh` | `_lzh` | `lzh` | Secondary | |
|
||||
| Japanese | `ja` | `ja` | `_ja` | `ja_jp` | Secondary | |
|
||||
| Spanish | `es` | `es` | `_es` | `es_es` | Secondary | [3gf8jv4dv](https://github.com/3gf8jv4dv) |
|
||||
| Russian | `ru` | `ru` | `_ru` | `ru_ru` | Secondary | [3gf8jv4dv](https://github.com/3gf8jv4dv) |
|
||||
| Ukrainian | `uk` | `uk` | `_uk` | `uk_ua` | Secondary | |
|
||||
|
||||
<details>
|
||||
<summary>About Language Tags</summary>
|
||||
|
||||
HMCL uses language tags that conform to the IETF BCP 47 standard.
|
||||
|
||||
When choosing language tags, we follow these principles:
|
||||
|
||||
1. For languages defined in the ISO 639 standard, if a tag has already been registered in the [IANA Language Subtag Registry](https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry),
|
||||
we always use the registered tag.
|
||||
|
||||
For example, for English, we use `en` instead of `eng` as the language code.
|
||||
|
||||
2. For non-standard languages defined by Minecraft, the code defined in the language file's `language.code` should be preferred over the game language file's name.
|
||||
|
||||
This is because Minecraft sometimes uses real-world country/region codes to represent joke languages
|
||||
(for example, Pirate English uses the language file `en_pt`, but `PT` is actually the country code for Portugal).
|
||||
|
||||
For example, for Upside down English, we use `en-Qabs` as the language code instead of `en-UD`.
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>About Localization Keys and File Suffixes</summary>
|
||||
|
||||
Localization file suffixes and keys are used to name [localization resources](#localization-resources).
|
||||
|
||||
Generally, the localization key is the language code for the resource, and the localization file suffix is obtained by replacing `-` with `_` in the language code and adding a leading underscore.
|
||||
|
||||
As a special case, for default resources, the localization key is `default` and the file suffix is empty.
|
||||
|
||||
Due to the existence of the [resource fallback mechanism](#resource-fallback-mechanism),
|
||||
if there is no resource that exactly matches the current locale,
|
||||
HMCL will derive a search list from the current language tag and search for resources in order.
|
||||
|
||||
We recommend always providing a default resource (with the `default` key and empty file suffix) when providing localization resources,
|
||||
to ensure all users can load resources properly.
|
||||
|
||||
We also recommend using broader language tags for localization resources whenever possible,
|
||||
so users are less likely to fall back to the default resource.
|
||||
|
||||
For example, if you provide a Simplified Chinese localization resource,
|
||||
we recommend using `zh` as the localization key instead of the more specific `zh-Hans`,
|
||||
so it will apply to all Chinese users and avoid falling back to the default resource for them.
|
||||
|
||||
If you want to provide both Simplified and Traditional Chinese resources,
|
||||
it is recommended to use the broader `zh` as the key for the resource with more users (as the default Chinese resource),
|
||||
and use the more specific `zh-Hans`/`zh-Hant` as the key for the resource with fewer users.
|
||||
|
||||
</details>
|
||||
|
||||
HMCL requires all pull requests that update documentation and localization resources to also update the resources
|
||||
for all **primary** supported languages.
|
||||
If the PR author is not familiar with the relevant languages, they can request translation help in the comments,
|
||||
and maintainers will help translate these texts before merging the PR.
|
||||
|
||||
For **secondary** supported languages, we cannot guarantee that these localization resources will always be updated in sync.
|
||||
We need collaborators who are proficient in these languages to help with maintenance.
|
||||
|
||||
We will record volunteers willing to help maintain these language resources in the documentation.
|
||||
If contributors want to have new localization texts translated into these languages in a timely manner,
|
||||
they can @ these volunteers in the PR for help.
|
||||
|
||||
If you are willing to help maintain localization resources for any language, please open a PR
|
||||
and add your GitHub username to the volunteer list above.
|
||||
We greatly appreciate your help.
|
||||
|
||||
## Adding Support for a New Language
|
||||
|
||||
HMCL welcomes anyone to participate in translation and contribution.
|
||||
However, maintaining translations for more languages requires more maintenance effort, so we have some requirements for newly added languages.
|
||||
Please confirm the following requirements before contributing:
|
||||
|
||||
- We prioritize [languages officially supported by Minecraft](https://minecraft.wiki/w/Language).
|
||||
|
||||
Unless there are special reasons, we do not provide support for languages not yet supported by Minecraft.
|
||||
- We hope to provide long-term maintenance support for all languages.
|
||||
|
||||
Since the maintainers of this project are proficient in only a limited number of languages,
|
||||
to avoid support for new languages quickly becoming outdated due to lack of maintainers,
|
||||
we hope to find people proficient in the language to help us maintain the newly added localization files in the long term.
|
||||
If there may be a lack of long-term maintainers, we will be more cautious about adding support for that language.
|
||||
|
||||
We recommend that contributors submit a [feature request](https://github.com/HMCL-dev/HMCL/issues/new?template=feature.yml) before providing a new language translation,
|
||||
discuss with other contributors first, and determine the future maintenance plan before starting the translation work.
|
||||
|
||||
### Getting Started with Translation
|
||||
|
||||
If you want to add support for a new language to HMCL, please start by translating [`I18N.properties`](../HMCL/src/main/resources/assets/lang/I18N.properties).
|
||||
The vast majority of HMCL's texts are in this file, and translating it will translate the entire interface.
|
||||
|
||||
This is a Java Properties file, which is very simple in format.
|
||||
Before translating, please read the introduction to this format: [Properties file](https://en.wikipedia.org/wiki/.properties).
|
||||
|
||||
As the first step of translation, please look up the two- or three-letter language tag for your language in [this table](https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry).
|
||||
For example, the language tag for English is `en`.
|
||||
|
||||
After determining the language tag, please create a file named `I18N_<localization file suffix>.properties` (e.g., `I18N_en.properties`) next to the [`I18N.properties` file](../HMCL/src/main/resources/assets/lang).
|
||||
Then you can start translating in this file.
|
||||
|
||||
The `I18N.properties` file follows the [resource fallback mechanism](#resource-fallback-mechanism) to look up missing translations.
|
||||
That is, you can translate entry by entry, and any untranslated entries will automatically fall back to English.
|
||||
|
||||
After translating part of the file, you can [build HMCL yourself](./README.md#compilation),
|
||||
and your translations will be included in the compiled HMCL.
|
||||
If your computer's default environment is not the target language,
|
||||
you can set the environment variable `HMCL_LANGUAGE` to the language tag you just found from the table,
|
||||
and HMCL will automatically switch to that language.
|
||||
|
||||
At this point, you can push the file to GitHub and submit a PR to HMCL.
|
||||
The maintainers of HMCL will complete the remaining steps for you.
|
||||
|
||||
## Localization Resources
|
||||
|
||||
All documentation and localization resource files follow the naming rule `<resource name><localization file suffix>.<extension>`.
|
||||
|
||||
For example, for `README.md`, the localized versions in different languages are named as follows:
|
||||
|
||||
- English: `README.md`
|
||||
- Chinese (Simplified): `README_zh.md`
|
||||
- Chinese (Traditional): `README_zh_Hant.md`
|
||||
- Chinese (Classical): `README_lzh.md`
|
||||
|
||||
In addition to localized files, HMCL also supports localizing certain text fields in JSON. Localized text in JSON uses the following format:
|
||||
|
||||
```json5
|
||||
{
|
||||
"<Localization Key 1>": "<Localized Text 1>",
|
||||
"<Localization Key 2>": "<Localized Text 2>",
|
||||
// ...
|
||||
"<Localization Key N>": "<Localized Text N>"
|
||||
}
|
||||
```
|
||||
|
||||
For example, for the following text field:
|
||||
|
||||
```json
|
||||
{
|
||||
"meow": "Meow"
|
||||
}
|
||||
```
|
||||
|
||||
It can be rewritten as localized text:
|
||||
|
||||
```json
|
||||
{
|
||||
"meow": {
|
||||
"default": "Meow",
|
||||
"zh": "喵呜",
|
||||
"zh-Hant": "喵嗚"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Resource Fallback Mechanism
|
||||
|
||||
For missing resources in a certain language, HMCL supports a resource fallback mechanism,
|
||||
which derives a search list based on different language tags and searches for resources in order according to this list.
|
||||
|
||||
Before searching, we first refine the language tag through the following steps.
|
||||
|
||||
1. Normalize Language Codes
|
||||
|
||||
If the language code subtag in the current language tag is not registered in the IANA Language Subtag Registry,
|
||||
HMCL will try to map it to a registered tag.
|
||||
|
||||
For example, HMCL will replace the language code `eng` with `en`.
|
||||
|
||||
2. Map Macrolanguages to Individual Languages
|
||||
|
||||
If the current language code is an [ISO 639 macrolanguage](https://en.wikipedia.org/wiki/ISO_639_macrolanguage),
|
||||
and the macrolanguage usually refers to a specific individual language, HMCL will replace it with that individual language.
|
||||
|
||||
For example, `zh` (Chinese) usually actually refers to `cmn` (Mandarin), so we replace the language code `zh` with `cmn`.
|
||||
|
||||
3. Derive Script
|
||||
|
||||
If the current language tag does not specify a script, HMCL will try to derive the script according to the following rules in order:
|
||||
|
||||
1. If the current language tag specifies a variant, and the variant is registered in the IANA Language Subtag Registry,
|
||||
and all its `Prefix` entries in the registry contain the same script, then set the current script to that script.
|
||||
|
||||
For example, if the current variant is `pinyin` (Chinese Pinyin), the script will be set to `Latn` (Latin).
|
||||
|
||||
2. If the current language code is assigned a `Suppress-Script` in the IANA Language Subtag Registry, set the current script to that script.
|
||||
|
||||
For example, if the current language code is `en` (English), the script will be set to `Latn` (Latin);
|
||||
if the code is `ru` (Russian), the script will be set to `Cyrl` (Cyrillic).
|
||||
|
||||
3. If the current language code is `lzh` (Classical Chinese), set the script to `Hant` (Traditional Chinese Characters).
|
||||
|
||||
4. If the current language code is `zh` or a sublanguage of `zh`, check if the current region code is one of `TW`, `HK`, or `MO`.
|
||||
If true, set the script to `Hant` (Traditional Chinese Characters);
|
||||
otherwise, set it to `Hans` (Simplified Chinese Characters).
|
||||
|
||||
After refining the language code, HMCL will derive a list of language tags based on this language tag.
|
||||
|
||||
For example, for the language tag `en-US`, HMCL will refine it to `en-Latn-US` and derive the following search list:
|
||||
|
||||
1. `en-Latn-US`
|
||||
2. `en-Latn`
|
||||
3. `en-US`
|
||||
4. `en`
|
||||
5. `und`
|
||||
|
||||
For the language tag `zh-CN`, HMCL will refine it to `cmn-Hans-CN` and derive the following search list:
|
||||
|
||||
1. `cmn-Hans-CN`
|
||||
2. `cmn-Hans`
|
||||
3. `cmn-CN`
|
||||
4. `cmn`
|
||||
5. `zh-Hans-CN`
|
||||
6. `zh-Hans`
|
||||
7. `zh-CN`
|
||||
8. `zh`
|
||||
9. `und`
|
||||
|
||||
For resources that can be merged (such as `.properties` files),
|
||||
HMCL will merge resources according to the priority of this list; for resources that are difficult to merge (such as font files),
|
||||
HMCL will load the highest-priority resource found in this list.
|
||||
|
||||
If the current language uses a three-letter ISO 639 code, but there is also a corresponding two-letter code,
|
||||
HMCL will map it to the two-letter code before searching for resources.
|
||||
|
||||
For example, if the current environment's language tag is `eng-US`,
|
||||
HMCL will map it to `en-US` and then search for localization resources according to the above rules.
|
||||
|
||||
### Additional Rules for Chinese
|
||||
|
||||
HMCL always adds `zh-CN` to the search list for all Chinese environments,
|
||||
and adds `zh-TW` to the search list for all Traditional Chinese environments.
|
||||
|
||||
Below are the localization resource search lists for several common Chinese environments.
|
||||
|
||||
- `zh-CN`:
|
||||
1. `cmn-Hans-CN`
|
||||
2. `cmn-Hans`
|
||||
3. `cmn-CN`
|
||||
4. `cmn`
|
||||
5. `zh-Hans-CN`
|
||||
6. `zh-Hans`
|
||||
7. `zh-CN`
|
||||
8. `zh`
|
||||
9. `und`
|
||||
- `zh-SG`:
|
||||
1. `cmn-Hans-SG`
|
||||
2. `cmn-Hans`
|
||||
3. `cmn-SG`
|
||||
4. `cmn`
|
||||
5. `zh-Hans-SG`
|
||||
6. `zh-Hans`
|
||||
7. `zh-SG`
|
||||
8. `zh-CN`
|
||||
9. `zh`
|
||||
10. `und`
|
||||
- `zh-TW`:
|
||||
1. `zh-Hant-TW`
|
||||
2. `zh-Hant`
|
||||
3. `zh-TW`
|
||||
4. `zh`
|
||||
5. `zh-CN`
|
||||
6. `und`
|
||||
- `zh-HK`:
|
||||
1. `cmn-Hant-HK`
|
||||
2. `cmn-Hant`
|
||||
3. `cmn-HK`
|
||||
4. `cmn`
|
||||
5. `zh-Hant-HK`
|
||||
6. `zh-Hant`
|
||||
7. `zh-HK`
|
||||
8. `zh-TW`
|
||||
9. `zh`
|
||||
10. `zh-CN`
|
||||
11. `und`
|
||||
- `lzh`:
|
||||
1. `lzh-Hant`
|
||||
2. `lzh`
|
||||
3. `zh-Hant`
|
||||
4. `zh-TW`
|
||||
5. `zh`
|
||||
6. `zh-CN`
|
||||
7. `und`
|
||||
|
||||
## Automatic Synchronization of Documentation Content
|
||||
|
||||
<!-- #BEGIN BLOCK -->
|
||||
<!-- #PROPERTY PROCESS_LINK=false -->
|
||||
To simplify documentation maintenance, HMCL uses a macro mechanism to automatically maintain parts of the documentation content.
|
||||
Run the following command in the terminal:
|
||||
|
||||
```bash
|
||||
./gradlew updateDocuments
|
||||
```
|
||||
|
||||
This will automatically update all documentation content.
|
||||
|
||||
For example, to create links for switching between different language versions of the same document,
|
||||
add the following content under the document title:
|
||||
|
||||
```markdown
|
||||
<!-- #BEGIN LANGUAGE_SWITCHER -->
|
||||
<!-- #END LANGUAGE_SWITCHER -->
|
||||
```
|
||||
|
||||
After running `./gradlew updateDocuments`, these two lines will be automatically replaced with language switcher links like the following:
|
||||
|
||||
```markdown
|
||||
**English** (**Standard**, [uʍoᗡ ǝpᴉsd∩](README_en_Qabs.md)) | 中文 ([简体](README_zh.md), [繁體](README_zh_Hant.md), [文言](README_lzh.md)) | [日本語](README_ja.md) | [español](README_es.md) | [русский](README_ru.md) | [українська](README_uk.md)
|
||||
```
|
||||
|
||||
For more about macros, see [MacroProcessor.java](../buildSrc/src/main/java/org/jackhuang/hmcl/gradle/docs/MacroProcessor.java).
|
||||
<!-- #END BLOCK -->
|
||||
+46
-102
@@ -1,8 +1,6 @@
|
||||
# 本地化
|
||||
|
||||
<!-- #BEGIN LANGUAGE_SWITCHER -->
|
||||
[English](Localization.md) | **中文**
|
||||
<!-- #END LANGUAGE_SWITCHER -->
|
||||
<!-- TODO: 本文档需要进一步完善。为了便于修改,我们暂时不将本文件翻译至其他语言,在完善后再在独立 PR 中提供其他语言的译文。 -->
|
||||
|
||||
HMCL 为多种语言提供本地化支持。
|
||||
|
||||
@@ -29,17 +27,19 @@ HMCL 为多种语言提供本地化支持。
|
||||
|
||||
HMCL 使用符合 IETF BCP 47 规范的语言标签。
|
||||
|
||||
在选择语言标签时,我们会遵循以下原则:
|
||||
对于 ISO 639 标准中定义的语言,如果同时存在两字母语言代码和三字母语言代码,那么应当优先选择两字母语言代码。
|
||||
|
||||
1. 对于 ISO 639 标准中定义的语言,如果已经在 [IANA 语言子标签注册表](https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry)中注册,我们总是使用经过注册的标签。
|
||||
例如,对于英语,我们使用 `en` 而不是 `eng` 作为语言代码。
|
||||
|
||||
例如,对于英语,我们使用 `en` 而不是 `eng` 作为语言代码。
|
||||
对于 Minecraft 所定义的非标准语言,应当优先使用语言文件的 `language.code` 中定义的代码,而非游戏语言文件的名称
|
||||
(但对于存在两字母代码的语言,应当将三字母语言代码替换为对应的两字母语言代码)。
|
||||
这是因为 Minecraft 有时候会用现实中实际存在的国家/地区代码来表示虚构语言 (比如说海盗英语的语言文件为 `en_pt`,但 `PT` 其实是葡萄牙的国家代码)。
|
||||
|
||||
2. 对于 Minecraft 所定义的非标准语言,应当优先使用语言文件的 `language.code` 中定义的代码,而非游戏语言文件的名称。
|
||||
例如,对于颠倒的英语,我们使用 `en-Qabs` 作为语言代码,而不是 `en-UD`。
|
||||
|
||||
这是因为 Minecraft 有时候会用现实中实际存在的国家/地区代码来表示虚构语言 (比如说海盗英语的语言文件为 `en_pt`,但 `PT` 其实是葡萄牙的国家代码)。
|
||||
此外,语言代码中应当尽可能选择地区中立的语言标签。
|
||||
|
||||
例如,对于颠倒的英语,我们使用 `en-Qabs` 作为语言代码,而不是 `en-UD`。
|
||||
例如,对于简体中文和繁体中文,我们使用 `zh-Hans`和 `zh-Hant` 作为语言代码,而不是 `zh-CN` 和 `zh-TW`。
|
||||
|
||||
</details>
|
||||
|
||||
@@ -106,10 +106,10 @@ HMCL 的绝大多数文本都位于这个文件中,翻译此文件就能翻译
|
||||
这是一个 Java Properties 文件,格式非常简单。
|
||||
在翻译前请先阅读该格式的介绍: [Properties 文件](https://en.wikipedia.org/wiki/.properties)。
|
||||
|
||||
作为翻译的第一步,请从[这张表格](https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry)中查询这个语言对应的两字母或三字母语言标签。
|
||||
作为翻译的第一步,请从[这张表格](https://en.wikipedia.org/wiki/List_of_ISO_639_language_codes)中查询这个语言对应的两字母或三字母语言标签。
|
||||
例如,英语的语言标签为 `en`。
|
||||
|
||||
在确定了语言标签后,请在 [`I18N.properties` 文件旁](../HMCL/src/main/resources/assets/lang)创建 `I18N_<本地化文件后缀>.properties` (例如 `I18N_en.properties`) 文件。
|
||||
在确定了语言标签后,请在 [`I18N.properties` 文件旁](../HMCL/src/main/resources/assets/lang)创建 `I18N_<语言标签>.properites` (例如 `I18N_en.properties`) 文件。
|
||||
随后,你就可以开始在这个文件中进行翻译工作了。
|
||||
|
||||
`I18N.properties` 文件会遵循[资源回退机制](#资源回退机制)查询缺失的译文。
|
||||
@@ -169,62 +169,12 @@ HMCL 的维护者会替你完成其他步骤。
|
||||
对于某个语言下的缺失的资源,HMCL 支持一套资源回退机制,会根据不同的语言标签推导出一个搜索列表,
|
||||
根据该列表依次搜索资源。
|
||||
|
||||
在搜索前,我们会先通过以下步骤对语言标签进行细化推导。
|
||||
例如,如果当前环境的语言标签为 `en-US`,那么 HMCL 会根据以下列表的顺序搜索对应的本地化资源:
|
||||
|
||||
1. 归一化语言代码
|
||||
|
||||
如果当前语言标签中的语言代码子标签未在 IANA 语言子标签注册表中进行注册,HMCL 会先尝试将其映射为注册表中已注册的标签。
|
||||
|
||||
例如,HMCL会将语言代码 `eng` 替换为 `en`。
|
||||
|
||||
2. 映射宏语言至子语言
|
||||
|
||||
如果当前语言代码是一个 [ISO 639 宏语言](https://en.wikipedia.org/wiki/ISO_639_macrolanguage),
|
||||
且该宏语言通常指代某个个体语言,HMCL 会将其替换为该个体语言。
|
||||
|
||||
例如 `zh` (中文) 通常实际指代 `cmn` (官话),所以我们会将语言代码 `zh` 替换为 `cmn`。
|
||||
|
||||
3. 推导拼写脚本
|
||||
|
||||
如果当前语言标签中未指定拼写脚本,HMCL 会依次根据以下规则尝试推导拼写脚本:
|
||||
|
||||
1. 如果当前语言标签指定了语言变体,该语言变体已在 IANA 语言子标签注册表中,
|
||||
且注册表中其所有 `Prefix` 都包含相同的拼写脚本,则将当前拼写脚本指定为该脚本。
|
||||
|
||||
例如,如果当前语言变体为 `pinyin` (汉语拼音),则当前拼写脚本会被指定为 `Latn` (拉丁文)。
|
||||
|
||||
2. 如果当前语言代码在 IANA 语言子标签注册表中被指定了 `Suppress-Script`,则将当前拼写脚本指定为该脚本。
|
||||
|
||||
例如,如果当前语言代码为 `en` (英语),则当前拼写脚本会被指定为 `Latn` (拉丁文);
|
||||
如果当前语言代码为 `ru` (俄语),则当前拼写脚本会被指定为 `Cyrl` (西里尔文)。
|
||||
|
||||
3. 如果当前语言代码是 `lzh` (文言),则将当前拼写脚本指定为 `Hant` (繁体汉字)。
|
||||
|
||||
4. 如果当前语言代码是 `zh` 或 `zh` 的子语言,则检查当前国家/地区代码是否为 `TW`、`HK`、`MO` 之一。
|
||||
如果结果为真,则将当前拼写脚本指定为 `Hant` (繁体汉字);否则将当前拼写脚本指定为 `Hans` (简体汉字)。
|
||||
|
||||
在对语言代码细化推导完成后,HMCL 会开始根据此语言标签推导出一个语言标签列表。
|
||||
|
||||
例如,对于语言标签 `en-US`,HMCL 会将其细化为 `en-Latn-US`,并据此推导出以下搜索列表:
|
||||
|
||||
1. `en-Latn-US`
|
||||
2. `en-Latn`
|
||||
3. `en-US`
|
||||
1. `en-US`
|
||||
2. `en`
|
||||
3. `und`
|
||||
|
||||
对于语言标签 `zh-CN`,HMCL 会将其细化为 `cmn-Hans-CN`,并据此推导出以下搜索列表:
|
||||
|
||||
1. `cmn-Hans-CN`
|
||||
2. `cmn-Hans`
|
||||
3. `cmn-CN`
|
||||
4. `cmn`
|
||||
5. `zh-Hans-CN`
|
||||
6. `zh-Hans`
|
||||
7. `zh-CN`
|
||||
8. `zh`
|
||||
9. `und`
|
||||
|
||||
对于能够混合的资源 (例如 `.properties` 文件),HMCL 会根据此列表的优先级混合资源;
|
||||
对于难以混合的资源 (例如字体文件),HMCL 会根据此列表加载找到的最高优先级的资源。
|
||||
|
||||
@@ -232,33 +182,35 @@ HMCL 的维护者会替你完成其他步骤。
|
||||
|
||||
例如,如果当前环境的语言标签为 `eng-US`,那么 HMCL 会将其映射至 `en-US` 后再根据上述规则搜索本地化资源。
|
||||
|
||||
如果当前语言是一个 [ISO 639 宏语言](https://en.wikipedia.org/wiki/ISO_639_macrolanguage)的子语言,那么 HMCL 也会搜索宏语言对应的资源。
|
||||
|
||||
### 对于中文的额外规则
|
||||
|
||||
HMCL 总是会将 `zh-CN` 加入所有中文环境的搜索列表中,将 `zh-TW` 加入所有繁体中文环境的搜索列表中。
|
||||
对于中文 (以及其子语言标签,例如文言文 (`lzh`)、普通话 (`cmn`)、粤语 (`yue`) 等等),HMCL 有着额外的支持。
|
||||
|
||||
如果当前环境的语言为中文 (及其子语言),且未指定书写脚本,那么 HMCL 会根据语言和地区标签推导出默认的书写脚本。
|
||||
|
||||
对于语言为 `lzh` 或地区为 `TW`、`HK`、`MO` 的情况,默认书写脚本为繁体中文 (`Hant`);
|
||||
而对于其他语言和地区,默认书写脚本为简体中文 (`Hans`)。
|
||||
|
||||
此外,HMCL 会将 `zh-CN` 加入所有中文环境的搜索列表中,将 `zh-TW` 加入所有繁体中文环境的搜索列表中,
|
||||
从而适应更多场景。
|
||||
|
||||
以下是几个常见中文环境对应的本地化资源搜索列表。
|
||||
|
||||
- `zh-CN`:
|
||||
1. `cmn-Hans-CN`
|
||||
2. `cmn-Hans`
|
||||
3. `cmn-CN`
|
||||
4. `cmn`
|
||||
5. `zh-Hans-CN`
|
||||
6. `zh-Hans`
|
||||
7. `zh-CN`
|
||||
8. `zh`
|
||||
9. `und`
|
||||
1. `zh-Hans-CN`
|
||||
2. `zh-Hans`
|
||||
3. `zh-CN`
|
||||
4. `zh`
|
||||
5. `und`
|
||||
- `zh-SG`:
|
||||
1. `cmn-Hans-SG`
|
||||
2. `cmn-Hans`
|
||||
3. `cmn-SG`
|
||||
4. `cmn`
|
||||
5. `zh-Hans-SG`
|
||||
6. `zh-Hans`
|
||||
7. `zh-SG`
|
||||
8. `zh-CN`
|
||||
9. `zh`
|
||||
10. `und`
|
||||
1. `zh-Hans-SG`
|
||||
2. `zh-Hans`
|
||||
3. `zh-SG`
|
||||
4. `zh-CN`
|
||||
5. `zh`
|
||||
6. `und`
|
||||
- `zh-TW`:
|
||||
1. `zh-Hant-TW`
|
||||
2. `zh-Hant`
|
||||
@@ -267,30 +219,22 @@ HMCL 总是会将 `zh-CN` 加入所有中文环境的搜索列表中,将 `zh-T
|
||||
5. `zh-CN`
|
||||
6. `und`
|
||||
- `zh-HK`:
|
||||
1. `cmn-Hant-HK`
|
||||
2. `cmn-Hant`
|
||||
3. `cmn-HK`
|
||||
4. `cmn`
|
||||
5. `zh-Hant-HK`
|
||||
6. `zh-Hant`
|
||||
7. `zh-HK`
|
||||
8. `zh-TW`
|
||||
9. `zh`
|
||||
10. `zh-CN`
|
||||
11. `und`
|
||||
- `lzh`:
|
||||
1. `lzh-Hant`
|
||||
2. `lzh`
|
||||
3. `zh-Hant`
|
||||
1. `zh-Hant-HK`
|
||||
2. `zh-Hant`
|
||||
3. `zh-HK`
|
||||
4. `zh-TW`
|
||||
5. `zh`
|
||||
6. `zh-CN`
|
||||
7. `und`
|
||||
- `lzh`:
|
||||
1. `lzh-Hant`
|
||||
2. `lzh`
|
||||
3. `zh-Hant`
|
||||
4. `zh`
|
||||
5. `und`
|
||||
|
||||
## 自动同步文档内容
|
||||
|
||||
<!-- #BEGIN BLOCK -->
|
||||
<!-- #PROPERTY PROCESS_LINK=false -->
|
||||
为了简化文档的维护,HMCL 使用了一套宏机制自动维护文档的部分内容。在命令行中执行
|
||||
|
||||
```bash
|
||||
@@ -309,8 +253,8 @@ HMCL 总是会将 `zh-CN` 加入所有中文环境的搜索列表中,将 `zh-T
|
||||
随后执行 `./gradlew updateDocuments`,这两行内容会被自动替换为类似这样的跳转链接:
|
||||
|
||||
```markdown
|
||||
**English** (**Standard**, [uʍoᗡ ǝpᴉsd∩](README_en_Qabs.md)) | 中文 ([简体](README_zh.md), [繁體](README_zh_Hant.md), [文言](README_lzh.md)) | [日本語](README_ja.md) | [español](README_es.md) | [русский](README_ru.md) | [українська](README_uk.md)
|
||||
**English** |
|
||||
中文 ([简体](README_zh.md), [繁體](README_zh.md), [文言](README_zh.md)) | [日本語](README_zh.md) | [español](README_zh.md) | [русский](README_zh.md) | [українська](README_zh.md)
|
||||
```
|
||||
|
||||
关于宏的更多内容,请见 [MacroProcessor.java](../buildSrc/src/main/java/org/jackhuang/hmcl/gradle/docs/MacroProcessor.java)。
|
||||
<!-- #END BLOCK -->
|
||||
Reference in new issue
Block a user