Skip to content

Commit

Permalink
默认从 en_us 中寻找文本
Browse files Browse the repository at this point in the history
  • Loading branch information
Gu-ZT committed Jan 8, 2025
1 parent 3964295 commit 742d89a
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/main/java/dev/anvilcraft/rg/api/server/TranslationUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,28 @@ public class TranslationUtil {
/**
* 将密钥转换为相应的文本,并可选择格式替换
*
* @param key 翻译键
* @param key 翻译键
* @param args 可选格式替换参数
* @return 翻译和格式化的文本
*/
public static @NotNull MutableComponent trans(String key, Object... args) {
return Component.translatableWithFallback(
key,
LANGUAGES.getOrDefault(RollingGateServerRules.language, new HashMap<>())
.getOrDefault(key, key)
.formatted(args),
LANGUAGES.getOrDefault(
RollingGateServerRules.language,
LANGUAGES.getOrDefault(
"en_us",
new HashMap<>()
)
).getOrDefault(key, key),
args
);
}

/**
* 为指定语言添加一组翻译
*
* @param language 语言代码
* @param language 语言代码
* @param translations 包含翻译的Map
*/
public static void addLanguage(String language, Map<String, String> translations) {
Expand All @@ -58,9 +62,9 @@ public static void addLanguage(String language, Map<String, String> translations
/**
* 从指定的命名空间和语言代码加载语言文件
*
* @param clazz 用于加载资源的类
* @param clazz 用于加载资源的类
* @param namespace 资源命名空间
* @param language 语言代码
* @param language 语言代码
*/
@SuppressWarnings("unchecked")
public static void loadLanguage(Class<?> clazz, String namespace, String language) {
Expand Down

0 comments on commit 742d89a

Please sign in to comment.