修复上传时服务端到客户端翻译键固定英文问题
This commit is contained in:
parent
da917d49e3
commit
32cc796498
|
|
@ -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;若并列,保留先到者
|
||||
|
|
|
|||
|
|
@ -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 "样板供应器";
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user