新增多语言处理方法
parent
1dcce55d72
commit
4615e23317
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue