1、多语言
This commit is contained in:
parent
e3be1c5218
commit
9f8f216a43
|
|
@ -0,0 +1,34 @@
|
||||||
|
package com.nflg.product.material.util;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import cn.hutool.extra.spring.SpringUtil;
|
||||||
|
import com.nflg.product.base.core.conmon.util.SessionUtil;
|
||||||
|
import com.nflg.product.material.pojo.entity.LanguageTranslationEntity;
|
||||||
|
import com.nflg.product.material.service.MaterialMainService;
|
||||||
|
import nflg.product.common.dto.LoginUserInfoDTO;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public class LanguageUtil {
|
||||||
|
|
||||||
|
private final String zhLanguage="zh-cn";
|
||||||
|
|
||||||
|
private Map<String, LanguageTranslationEntity> translationMap;
|
||||||
|
|
||||||
|
public LanguageUtil() {
|
||||||
|
List<LanguageTranslationEntity> keyLanguage = SpringUtil.getBean(MaterialMainService.class).getBaseMapper().getKeyLanguage(SessionUtil.getLanguage());
|
||||||
|
|
||||||
|
if(CollUtil.isEmpty(keyLanguage)){
|
||||||
|
keyLanguage = SpringUtil.getBean(MaterialMainService.class).getBaseMapper().getKeyLanguage(zhLanguage);
|
||||||
|
}
|
||||||
|
translationMap=ListCommonUtil.listToMap(keyLanguage,LanguageTranslationEntity::getKeyName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTranslationTextByKeyName(String keyName){
|
||||||
|
|
||||||
|
return translationMap.containsKey(keyName)? translationMap.get(keyName).getTranslationText():"";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -85,7 +85,7 @@ public class SessionUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getLanguage() {
|
public static String getLanguage() {
|
||||||
return Optional.ofNullable(loginUser.get()).map(LoginUserInfoDTO::getLanguage).orElse(null);
|
return Optional.ofNullable(loginUser.get()).map(LoginUserInfoDTO::getLanguage).orElse("");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getSessionKey() {
|
public static String getSessionKey() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue