添加文言文支持 (#4348)

This commit is contained in:
Glavo 2025-08-29 14:42:10 +08:00 committed by GitHub
parent 55816032b7
commit 67e4dddda1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 1251 additions and 18 deletions

View File

@ -28,6 +28,7 @@ import org.jackhuang.hmcl.util.versioning.GameVersionNumber;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Locale;
import java.util.Map; import java.util.Map;
import static org.jackhuang.hmcl.util.logging.Logger.LOG; import static org.jackhuang.hmcl.util.logging.Logger.LOG;
@ -71,11 +72,6 @@ public final class HMCLGameLauncher extends DefaultLauncher {
} }
} }
if (!I18n.isUseChinese()) {
return;
}
String lang;
/* /*
1.0- 没有语言选项遇到这些版本时不设置 1.0- 没有语言选项遇到这些版本时不设置
1.1 ~ 5 zh_CN 时正常zh_cn 时崩溃最后两位字母必须大写否则将会 NPE 崩溃 1.1 ~ 5 zh_CN 时正常zh_cn 时崩溃最后两位字母必须大写否则将会 NPE 崩溃
@ -84,20 +80,27 @@ public final class HMCLGameLauncher extends DefaultLauncher {
1.13+ zh_cn 时正常zh_CN 时自动切换为英文 1.13+ zh_cn 时正常zh_CN 时自动切换为英文
*/ */
GameVersionNumber gameVersion = GameVersionNumber.asGameVersion(repository.getGameVersion(version)); GameVersionNumber gameVersion = GameVersionNumber.asGameVersion(repository.getGameVersion(version));
if (gameVersion.compareTo("1.1") < 0) { if (gameVersion.compareTo("1.1") < 0)
lang = null; return;
} else if (gameVersion.compareTo("1.11") < 0) {
String lang;
if (I18n.isUseChinese()) {
lang = "zh_CN"; lang = "zh_CN";
} else if (Locale.getDefault().getLanguage().equals("lzh")) {
lang = "lzh";
} else { } else {
lang = "zh_cn"; return;
} }
if (lang != null) { if (gameVersion.compareTo("1.11") >= 0) {
try { lang = lang.toLowerCase(Locale.ROOT);
FileUtils.writeText(optionsFile, String.format("lang:%s\n", lang)); }
} catch (IOException e) {
LOG.warning("Unable to generate options.txt", e); try {
} FileUtils.writeText(optionsFile, String.format("lang:%s\n", lang));
} catch (IOException e) {
LOG.warning("Unable to generate options.txt", e);
} }
} }

View File

@ -129,8 +129,12 @@ public final class FontManager {
return null; return null;
try { try {
Locale locale = Locale.getDefault();
if (locale.getLanguage().equals("lzh"))
locale = Locale.TRADITIONAL_CHINESE;
String result = SystemUtils.run(fcMatch.toString(), String result = SystemUtils.run(fcMatch.toString(),
":lang=" + Locale.getDefault().toLanguageTag(), ":lang=" + locale.toLanguageTag(),
"--format", "%{family}\\n%{file}").trim(); "--format", "%{family}\\n%{file}").trim();
String[] results = result.split("\\n"); String[] results = result.split("\\n");

View File

@ -20,7 +20,6 @@ package org.jackhuang.hmcl.util.i18n;
import com.google.gson.annotations.JsonAdapter; import com.google.gson.annotations.JsonAdapter;
import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter; import com.google.gson.stream.JsonWriter;
import org.jackhuang.hmcl.util.Lang;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
@ -63,7 +62,12 @@ public final class Locales {
*/ */
public static final SupportedLocale ZH_CN = new SupportedLocale(Locale.SIMPLIFIED_CHINESE); public static final SupportedLocale ZH_CN = new SupportedLocale(Locale.SIMPLIFIED_CHINESE);
public static final List<SupportedLocale> LOCALES = Lang.immutableListOf(DEFAULT, EN, ES, JA, RU, ZH_CN, ZH); /**
* Wenyan (Classical Chinese)
*/
public static final SupportedLocale WENYAN = new SupportedLocale(Locale.forLanguageTag("lzh"));
public static final List<SupportedLocale> LOCALES = List.of(DEFAULT, EN, ES, JA, RU, ZH_CN, ZH, WENYAN);
public static SupportedLocale getLocaleByName(String name) { public static SupportedLocale getLocaleByName(String name) {
if (name == null) return DEFAULT; if (name == null) return DEFAULT;
@ -80,6 +84,8 @@ public final class Locales {
return ZH; return ZH;
case "zh_cn": case "zh_cn":
return ZH_CN; return ZH_CN;
case "lzh":
return WENYAN;
default: default:
return DEFAULT; return DEFAULT;
} }
@ -92,6 +98,7 @@ public final class Locales {
else if (locale == JA) return "ja"; else if (locale == JA) return "ja";
else if (locale == ZH) return "zh"; else if (locale == ZH) return "zh";
else if (locale == ZH_CN) return "zh_CN"; else if (locale == ZH_CN) return "zh_CN";
else if (locale == WENYAN) return "lzh";
else if (locale == DEFAULT) return "def"; else if (locale == DEFAULT) return "def";
else throw new IllegalArgumentException("Unknown locale: " + locale); else throw new IllegalArgumentException("Unknown locale: " + locale);
} }
@ -115,6 +122,20 @@ public final class Locales {
if (resourceBundle == null) { if (resourceBundle == null) {
if (this != DEFAULT && this.locale == DEFAULT.locale) { if (this != DEFAULT && this.locale == DEFAULT.locale) {
bundle = DEFAULT.getResourceBundle(); bundle = DEFAULT.getResourceBundle();
} else if (this == WENYAN) {
bundle = ResourceBundle.getBundle("assets.lang.I18N", locale, new ResourceBundle.Control() {
@Override
public List<Locale> getCandidateLocales(String baseName, Locale locale) {
if (locale.getLanguage().equals("lzh")) {
return List.of(
locale,
Locale.forLanguageTag("zh"),
Locale.ROOT
);
}
return super.getCandidateLocales(baseName, locale);
}
});
} else { } else {
bundle = ResourceBundle.getBundle("assets.lang.I18N", locale); bundle = ResourceBundle.getBundle("assets.lang.I18N", locale);
} }

File diff suppressed because it is too large Load Diff