新增多语言处理方法

main
yushun.ding 2023-03-25 00:26:00 +08:00
parent 1dcce55d72
commit 4615e23317
1 changed files with 66 additions and 0 deletions

View File

@ -3870,4 +3870,70 @@ public class Util extends weaver.general.Util {
}
return ip;
}
/**
*
*
* @param oldName
* @param newName
* @param lanuage 7 8 9
*/
public String moreLanugageHandler(String oldName, String newName, String lanuage) {
List languageIds = weaver.general.Util.getActiveLanguageIds();//获取系统支持的多语言
String newMoreLanuage = "";
//要按照当前系统支持的多语言id进行拼接处理
if (oldName.startsWith("~`~`") && oldName.endsWith("`~`~")) {
// 获取当前系统存在的多语言id
// 思路先按照系统存在的语言进行拼接之后判断oldname包含那些语言进行过滤将除了lanuage的其他语言都替换成之前的
//多语言的中间处理
String tempLanuage = joinLanuage(newName, languageIds);
//中间处理转成map
Map splitMultilangData = weaver.general.Util.splitMultilangData(tempLanuage);
Map<String, String> lanuageMap = new HashMap<>();
for (Object id : languageIds) {
String labelLanuage = "`~`" + id;
if (oldName.contains(labelLanuage)) {
//获取过滤的语言name
String formatLanuageName = weaver.general.Util.formatMultiLang(oldName, String.valueOf(id));
if (!weaver.general.StringUtil.isEmpty(formatLanuageName)) {
lanuageMap.put(String.valueOf(id), formatLanuageName);
}
}
}
String s = lanuageMap.get(lanuage);
if (weaver.general.StringUtil.isEmpty(s)) {
for (Map.Entry<String, String> entry : lanuageMap.entrySet()) {
splitMultilangData.put(entry.getKey(), entry.getValue());
}
} else {
lanuageMap.remove(lanuage);
for (Map.Entry<String, String> entry : lanuageMap.entrySet()) {
splitMultilangData.put(entry.getKey(), entry.getValue());
}
}
newMoreLanuage = weaver.general.Util.stitchMultilangData(splitMultilangData);
} else {
//要根据系统支持的语言进行拼接
newMoreLanuage = joinLanuage(newName, languageIds);
}
return newMoreLanuage;
}
/**
*
*
* @param newName
* @param languageIds
* @return
*/
public String joinLanuage(String newName, List languageIds) {
StringBuilder supportLanuage = new StringBuilder();
supportLanuage.append("~`~`");
languageIds.forEach(id -> {
supportLanuage.append(id).append(" ").append(newName).append("`~`");
});
supportLanuage.delete(supportLanuage.lastIndexOf("`~`"), supportLanuage.length());
supportLanuage.append("`~`~");
return supportLanuage.toString();
}
}