-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
99 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
package dev.anvilcraft.rg; | ||
|
||
public class RollingGateCategories { | ||
public static final String DISABLED = "DISABLED"; | ||
public static final String DISABLED = "disabled"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package dev.anvilcraft.rg.util; | ||
|
||
import com.google.gson.Gson; | ||
import dev.anvilcraft.rg.RollingGate; | ||
import dev.anvilcraft.rg.RollingGateRules; | ||
import net.minecraft.network.chat.Component; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class TranslationUtil { | ||
public static final Gson GSON = new Gson(); | ||
public static final Map<String, Map<String, String>> LANGUAGES = new HashMap<>(); | ||
|
||
public static @NotNull String trans(String key) { | ||
return LANGUAGES.getOrDefault(RollingGateRules.language, new HashMap<>()).getOrDefault(key, key); | ||
} | ||
|
||
public static @NotNull Component trans(String key, Object... args) { | ||
return Component.translatableWithFallback( | ||
key, | ||
LANGUAGES.getOrDefault(RollingGateRules.language, new HashMap<>()) | ||
.getOrDefault(key, key) | ||
.formatted(args), | ||
args | ||
); | ||
} | ||
|
||
public static void addLanguage(String language, Map<String, String> translations) { | ||
Map<String, String> languages = LANGUAGES.getOrDefault(language, new HashMap<>()); | ||
languages.putAll(translations); | ||
LANGUAGES.putIfAbsent(language, languages); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public static void loadLanguage(Class<?> clazz, String namespace, String language) { | ||
try ( | ||
InputStream stream = clazz.getResourceAsStream("/assets/%s/lang/%s.json".formatted(namespace, language)); | ||
) { | ||
if (stream == null) { | ||
RollingGate.LOGGER.error("Can't find language {}/{}.", namespace, language); | ||
return; | ||
} | ||
try (InputStreamReader reader = new InputStreamReader(stream)) { | ||
TranslationUtil.addLanguage("zh_cn", (Map<String, String>) TranslationUtil.GSON.fromJson(reader, Map.class)); | ||
RollingGate.LOGGER.info("Loaded {} language file.", language); | ||
} | ||
} catch (IOException e) { | ||
RollingGate.LOGGER.error("Failed to load %s language file.".formatted(language), e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"rolling_gate.rolling_gate.rule.language": "Language", | ||
"rolling_gate.rolling_gate.rule.language.desc": "Set the default language for RollingGate", | ||
|
||
"rolling_gate.category.disabled": "DISABLED" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"rolling_gate.rolling_gate.rule.language": "语言", | ||
"rolling_gate.rolling_gate.rule.language.desc": "设置卷帘门的默认语言", | ||
|
||
"rolling_gate.category.disabled": "禁用类" | ||
} |