From 4615e23317d81587f18ff51014674b724767a6f6 Mon Sep 17 00:00:00 2001 From: "yushun.ding" <2437588377@qq.com> Date: Sat, 25 Mar 2023 00:26:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=A4=9A=E8=AF=AD=E8=A8=80?= =?UTF-8?q?=E5=A4=84=E7=90=86=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/aiyh/utils/Util.java | 66 ++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/src/main/java/aiyh/utils/Util.java b/src/main/java/aiyh/utils/Util.java index cc5f158..62322df 100644 --- a/src/main/java/aiyh/utils/Util.java +++ b/src/main/java/aiyh/utils/Util.java @@ -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 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 entry : lanuageMap.entrySet()) { + splitMultilangData.put(entry.getKey(), entry.getValue()); + } + } else { + lanuageMap.remove(lanuage); + for (Map.Entry 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(); + } }