mirror of https://gitee.com/stylefeng/roses
【i18n】更新菜单的多语言翻译
parent
b0d64d951d
commit
f22877c67a
|
@ -49,8 +49,13 @@ public interface RuleConstants {
|
|||
String RULE_EXCEPTION_STEP_CODE = "01";
|
||||
|
||||
/**
|
||||
* 一级公司的父级id
|
||||
* 一级公司的父级id
|
||||
*/
|
||||
Long TREE_ROOT_ID = -1L;
|
||||
|
||||
/**
|
||||
* 中文的多语言类型编码
|
||||
*/
|
||||
String CHINES_TRAN_LANGUAGE_CODE = "chinese";
|
||||
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import cn.hutool.core.util.StrUtil;
|
|||
import cn.stylefeng.roses.kernel.auth.api.enums.DataScopeTypeEnum;
|
||||
import cn.stylefeng.roses.kernel.auth.api.pojo.login.basic.SimpleRoleInfo;
|
||||
import cn.stylefeng.roses.kernel.auth.api.pojo.login.basic.SimpleUserInfo;
|
||||
import cn.stylefeng.roses.kernel.rule.constants.RuleConstants;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
@ -101,7 +102,7 @@ public class LoginUser implements Serializable {
|
|||
* <p>
|
||||
* 默认语种是中文
|
||||
*/
|
||||
private String tranLanguageCode = "chinese";
|
||||
private String tranLanguageCode = RuleConstants.CHINES_TRAN_LANGUAGE_CODE;
|
||||
|
||||
public String getWsUrl() {
|
||||
AtomicReference<String> returnUrl = new AtomicReference<>(StrUtil.EMPTY);
|
||||
|
|
|
@ -18,4 +18,9 @@ public interface TranslationConstants {
|
|||
*/
|
||||
String I18N_EXCEPTION_STEP_CODE = "25";
|
||||
|
||||
/**
|
||||
* 菜单类型的tranCode前缀
|
||||
*/
|
||||
String TRAN_CODE_MENU_PREFIX = "MENU_";
|
||||
|
||||
}
|
||||
|
|
|
@ -24,6 +24,14 @@
|
|||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
|
||||
<!--多语言翻译api模块-->
|
||||
<!--用在菜单翻译上-->
|
||||
<dependency>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>i18n-api</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
|
||||
<!--资源api模块-->
|
||||
<!--用在资源控制器,资源扫描上-->
|
||||
<dependency>
|
||||
|
|
|
@ -1,18 +1,20 @@
|
|||
package cn.stylefeng.roses.kernel.menu.modular.factory;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import cn.stylefeng.roses.kernel.auth.api.context.LoginContext;
|
||||
import cn.stylefeng.roses.kernel.i18n.api.constants.TranslationConstants;
|
||||
import cn.stylefeng.roses.kernel.i18n.api.context.TranslationContext;
|
||||
import cn.stylefeng.roses.kernel.menu.modular.entity.SysMenu;
|
||||
import cn.stylefeng.roses.kernel.rule.constants.RuleConstants;
|
||||
import cn.stylefeng.roses.kernel.rule.factory.DefaultTreeBuildFactory;
|
||||
import cn.stylefeng.roses.kernel.rule.util.HttpServletUtil;
|
||||
import cn.stylefeng.roses.kernel.system.AppServiceApi;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.menu.layui.LayuiAppIndexMenus;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.menu.layui.LayuiIndexMenuTreeNode;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
|
@ -59,6 +61,16 @@ public class LayuiMenusFactory {
|
|||
// 每个节点的url要加上context-path
|
||||
layuiIndexMenuTreeNode.setLayuiPath(contextPath + appMenu.getLayuiPath());
|
||||
|
||||
// 如果当前用户时非中文状态,则翻译菜单
|
||||
String tranLanguageCode = LoginContext.me().getLoginUser().getTranLanguageCode();
|
||||
if (!RuleConstants.CHINES_TRAN_LANGUAGE_CODE.equals(tranLanguageCode)) {
|
||||
Map<String, String> tranDictBook = TranslationContext.me().getTranslationDictByLanguage(tranLanguageCode);
|
||||
String translatedName = tranDictBook.get(TranslationConstants.TRAN_CODE_MENU_PREFIX + appMenu.getMenuCode().toUpperCase());
|
||||
if (StrUtil.isNotBlank(translatedName)) {
|
||||
layuiIndexMenuTreeNode.setMenuName(translatedName);
|
||||
}
|
||||
}
|
||||
|
||||
layuiIndexMenuTreeNodes.add(layuiIndexMenuTreeNode);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue