优化模组中文译名展示方式 (#4636)

1. 隐藏不包含中文字符的译名
2. 过滤译名中的 Emoji
This commit is contained in:
Glavo
2025-10-09 16:34:33 +08:00
committed by GitHub
parent 96f16382c0
commit c8edf4be62
2 changed files with 36 additions and 5 deletions

View File

@@ -632,10 +632,28 @@ final class ModListPageSkin extends SkinBase<ModListPage> {
}).start(); }).start();
} }
if (modTranslations != null && I18n.isUseChinese() && !modInfo.getName().equals(modTranslations.getName()))
content.setTitle(modInfo.getName() + " (" + modTranslations.getName() + ")"); String displayName = modInfo.getName();
else if (modTranslations != null && I18n.isUseChinese()) {
content.setTitle(modInfo.getName()); String chineseName = modTranslations.getName();
if (StringUtils.containsChinese(chineseName)) {
if (StringUtils.containsEmoji(chineseName)) {
StringBuilder builder = new StringBuilder();
chineseName.codePoints().forEach(ch -> {
if (ch < 0x1F300 || ch > 0x1FAFF)
builder.appendCodePoint(ch);
});
chineseName = builder.toString().trim();
}
if (StringUtils.isNotBlank(chineseName) && !displayName.equalsIgnoreCase(chineseName)) {
displayName = displayName + " (" + chineseName + ")";
}
}
}
content.setTitle(displayName);
StringJoiner joiner = new StringJoiner(" | "); StringJoiner joiner = new StringJoiner(" | ");

View File

@@ -87,7 +87,7 @@ public final class StringUtils {
builder.append(str, start, i); builder.append(str, start, i);
} }
builder.append(' '); builder.append(' ');
i = whitespaceEnd ; i = whitespaceEnd;
continue; continue;
} }
} }
@@ -261,6 +261,19 @@ public final class StringUtils {
return false; return false;
} }
public static boolean containsEmoji(String str) {
for (int i = 0; i < str.length(); ) {
int ch = str.codePointAt(i);
if (ch >= 0x1F300 && ch <= 0x1FAFF)
return true;
i += Character.charCount(ch);
}
return false;
}
private static boolean isVarNameStart(char ch) { private static boolean isVarNameStart(char ch) {
return (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || ch == '_'; return (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || ch == '_';
} }