81 lines
4.3 KiB
Diff
81 lines
4.3 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Helvetica Volubi <suisuroru@blue-millennium.fun>
|
|
Date: Thu, 12 Jun 2025 04:44:24 +0800
|
|
Subject: [PATCH] I18n support
|
|
|
|
|
|
diff --git a/net/minecraft/locale/Language.java b/net/minecraft/locale/Language.java
|
|
index 7b9e2a1a208b46a69c16e6afd8b502259893574f..cdd26bbc6f6ff5510347049706e0f6f344fe79b1 100644
|
|
--- a/net/minecraft/locale/Language.java
|
|
+++ b/net/minecraft/locale/Language.java
|
|
@@ -31,11 +31,27 @@ public abstract class Language {
|
|
public static final String DEFAULT = "en_us";
|
|
private static volatile Language instance = loadDefault();
|
|
|
|
+ // Lophine start - I18n support
|
|
private static Language loadDefault() {
|
|
+ return load("/assets/minecraft/lang/" + DEFAULT + ".json");
|
|
+ }
|
|
+
|
|
+ public static void loadLocalLang(String lang) {
|
|
+ try {
|
|
+ inject(load(lang));
|
|
+ } catch (Exception e) {
|
|
+ LOGGER.error("Failed to load language file for {}", me.earthme.lophine.config.modules.optimizations.LanguageConfig.lang, e);
|
|
+ inject(loadDefault());
|
|
+ }
|
|
+ }
|
|
+
|
|
+ // Lophine end - I18n support
|
|
+
|
|
+ private static Language load(String lang) { // Lophine - I18n support
|
|
DeprecatedTranslationsInfo deprecatedTranslationsInfo = DeprecatedTranslationsInfo.loadFromDefaultResource();
|
|
Map<String, String> map = new HashMap<>();
|
|
BiConsumer<String, String> biConsumer = map::put;
|
|
- parseTranslations(biConsumer, "/assets/minecraft/lang/en_us.json");
|
|
+ parseTranslations(biConsumer, lang); // Lophine - I18n support
|
|
deprecatedTranslationsInfo.applyToMap(map);
|
|
final Map<String, String> map1 = Map.copyOf(map);
|
|
return new Language() {
|
|
@@ -65,13 +81,26 @@ public abstract class Language {
|
|
};
|
|
}
|
|
|
|
+ // Lophine start - I18n support
|
|
private static void parseTranslations(BiConsumer<String, String> output, String languagePath) {
|
|
try (InputStream resourceAsStream = Language.class.getResourceAsStream(languagePath)) {
|
|
loadFromJson(resourceAsStream, output);
|
|
- } catch (JsonParseException | IOException var7) {
|
|
- LOGGER.error("Couldn't read strings from {}", languagePath, var7);
|
|
+ } catch (Exception e) {
|
|
+ try {
|
|
+ java.nio.file.Path filePath = java.nio.file.Paths.get(languagePath);
|
|
+ try (InputStream fileStream = java.nio.file.Files.newInputStream(filePath)) {
|
|
+ loadFromJson(fileStream, output);
|
|
+ } catch (java.nio.file.NoSuchFileException fileEx) {
|
|
+ LOGGER.error("Language file not found in both locations: {}", languagePath);
|
|
+ } catch (Exception fileEx) {
|
|
+ LOGGER.error("Failed to load from filesystem {}", filePath, fileEx);
|
|
+ }
|
|
+ } catch (Exception ep) {
|
|
+ LOGGER.error("Couldn't read strings from {}", languagePath, ep);
|
|
+ }
|
|
}
|
|
}
|
|
+ // Lophine end - I18n support
|
|
|
|
public static void loadFromJson(InputStream stream, BiConsumer<String, String> output) {
|
|
JsonObject jsonObject = GSON.fromJson(new InputStreamReader(stream, StandardCharsets.UTF_8), JsonObject.class);
|
|
diff --git a/net/minecraft/server/dedicated/DedicatedServer.java b/net/minecraft/server/dedicated/DedicatedServer.java
|
|
index ba0cdba050cd3bf9231e15dd9543d34f37d9dae5..ce7d70afa524e5b8ea6f9de75d34c8f1eaa6ad72 100644
|
|
--- a/net/minecraft/server/dedicated/DedicatedServer.java
|
|
+++ b/net/minecraft/server/dedicated/DedicatedServer.java
|
|
@@ -172,6 +172,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
|
|
this.paperConfigurations.initializeWorldDefaultsConfiguration(this.registryAccess());
|
|
// Paper end - initialize global and world-defaults configuration
|
|
me.earthme.lophine.config.LophineConfig.loadConfigFiles(); //Luminol - load config file // Lophine - load config file
|
|
+ me.earthme.lophine.utils.LocalLangUtil.init(); // Lophine - I18n support
|
|
if (false) this.server.spark.enableEarlyIfRequested(); // Paper - spark // Luminol - Force disable builtin spark
|
|
// Paper start - fix converting txt to json file; convert old users earlier after PlayerList creation but before file load/save
|
|
if (this.convertOldUsers()) {
|