2025-06-22 03:19:06 +03:00
|
|
|
package hdvtdev.blockAndSeek;
|
|
|
|
|
|
2025-06-28 00:36:06 +03:00
|
|
|
import hdvtdev.blockAndSeek.managers.ConfigManager;
|
2025-06-22 03:19:06 +03:00
|
|
|
import net.kyori.adventure.text.Component;
|
|
|
|
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
2025-06-28 00:36:06 +03:00
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
|
import org.jetbrains.annotations.Nullable;
|
2025-06-22 03:19:06 +03:00
|
|
|
|
2025-06-28 00:36:06 +03:00
|
|
|
import java.util.Collections;
|
2025-06-22 03:19:06 +03:00
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
public class Localization {
|
|
|
|
|
|
2025-06-28 00:36:06 +03:00
|
|
|
private static volatile Map<String, Map<String, String>> localization = Collections.unmodifiableMap(ConfigManager.getLocalization());
|
2025-06-26 01:18:01 +03:00
|
|
|
private static final MiniMessage miniMessage = MiniMessage.miniMessage();
|
|
|
|
|
private static final Component prefix = miniMessage.deserialize("<gold>[<bold><blue>BlockAndSeek<reset><gold>] ");
|
2025-06-22 03:19:06 +03:00
|
|
|
|
2025-06-28 00:36:06 +03:00
|
|
|
public static void update() {
|
|
|
|
|
localization = Collections.unmodifiableMap(ConfigManager.getLocalization());
|
2025-06-22 03:19:06 +03:00
|
|
|
}
|
|
|
|
|
|
2025-06-28 00:36:06 +03:00
|
|
|
public static String get(@NotNull String key, String... replacements) {
|
|
|
|
|
return getLang(null, key, replacements);
|
2025-06-22 03:19:06 +03:00
|
|
|
}
|
|
|
|
|
|
2025-06-28 00:36:06 +03:00
|
|
|
public static String getLang(@Nullable String lang, @NotNull String key, String... replacements) {
|
|
|
|
|
lang = lang == null || !localization.containsKey(lang) ? "en-US" : lang;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String s = localization.get(lang).get(key);
|
2025-06-26 01:18:01 +03:00
|
|
|
if (s != null) {
|
|
|
|
|
for (int i = 0; i < replacements.length; i += 2) {
|
|
|
|
|
s = s.replace(replacements[i], replacements[i + 1]);
|
|
|
|
|
}
|
|
|
|
|
} else return "Unknown localization: " + key;
|
|
|
|
|
return s;
|
|
|
|
|
}
|
2025-06-22 03:19:06 +03:00
|
|
|
|
2025-06-26 01:18:01 +03:00
|
|
|
public static Component getComponent(String key, String... replacements) {
|
2025-06-28 00:36:06 +03:00
|
|
|
return getLangComponent(null, key, replacements);
|
2025-06-22 03:19:06 +03:00
|
|
|
}
|
|
|
|
|
|
2025-06-28 00:36:06 +03:00
|
|
|
public static Component getLangComponent(String lang, String key, String... replacements) {
|
|
|
|
|
return miniMessage.deserialize(getLang(lang, key, replacements));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Component getLangComponentWithPrefix(String lang, String key, String... replacements) {
|
|
|
|
|
return prefix.append(getLangComponent(lang, key, replacements));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Component getComponentWithPrefix(String key, String... replacements) {
|
|
|
|
|
return prefix.append(getLangComponent(null, key, replacements));
|
|
|
|
|
}
|
2025-06-22 03:19:06 +03:00
|
|
|
|
|
|
|
|
}
|