修复上传时服务端到客户端翻译键固定英文问题

This commit is contained in:
GaLicn 2025-09-30 12:29:49 +08:00
parent da917d49e3
commit 32cc796498
2 changed files with 32 additions and 3 deletions

View File

@ -183,10 +183,29 @@ public class ProviderSelectScreen extends Screen {
}
}
/**
* 将服务器发送的名称可能是 Component JSON反序列化为本地化文本
*/
private String deserializeComponentName(String name) {
try {
// 如果名称是 JSON 格式的 Component反序列化后获取本地化文本
if (name.startsWith("{") || name.startsWith("\"")) {
Component component = Component.Serializer.fromJson(name);
if (component != null) {
return component.getString();
}
}
} catch (Exception e) {
// 如果不是 JSON 或解析失败使用原始字符串
}
return name;
}
private String buildLabel(int idx) {
String name = fNames.get(idx);
int totalSlots = fTotalSlots.get(idx);
int count = fCount.get(idx);
// 不显示具体 id显示合并统计名称总空位x数量
return name + " (" + totalSlots + ") x" + count;
}
@ -215,7 +234,11 @@ public class ProviderSelectScreen extends Screen {
String name = names.get(i);
long id = ids.get(i);
int slots = emptySlots.get(i);
Group g = map.computeIfAbsent(name, k -> new Group());
// Component JSON 转换为本地化文本用于分组键
String groupKey = deserializeComponentName(name);
Group g = map.computeIfAbsent(groupKey, k -> new Group());
g.count++;
g.totalSlots += Math.max(0, slots);
// 挑选空位最多的作为代表 id若并列保留先到者

View File

@ -941,7 +941,9 @@ public class ExtendedAEPatternUploadUtil {
// 尝试获取供应器的组信息来构建显示名称
var group = container.getTerminalGroup();
if (group != null) {
return group.name().getString();
// 使用 Component 序列化来保持翻译键而不是直接 getString()
// 这样客户端可以根据自己的语言设置进行翻译
return Component.Serializer.toJson(group.name());
}
} catch (Exception e) {
// 忽略异常使用默认名称
@ -1183,7 +1185,11 @@ public class ExtendedAEPatternUploadUtil {
if (container == null) return "未知供应器";
try {
var group = container.getTerminalGroup();
if (group != null) return group.name().getString();
if (group != null) {
// 使用 Component 序列化来保持翻译键而不是直接 getString()
// 这样客户端可以根据自己的语言设置进行翻译
return Component.Serializer.toJson(group.name());
}
} catch (Throwable ignored) {
}
return "样板供应器";