feat(i18n): add backend i18n properties, Flyway migration, and dictionary multi-language support
This commit is contained in:
@@ -55,6 +55,12 @@ public class SysDictData extends BaseEntity {
|
||||
/** 拼音首字母 */
|
||||
private String pyStr;
|
||||
|
||||
/** 字典英文值 */
|
||||
private String dictValueEn;
|
||||
|
||||
/** 字典越南文值 */
|
||||
private String dictValueVi;
|
||||
|
||||
public Long getDictCode() {
|
||||
return dictCode;
|
||||
}
|
||||
@@ -146,12 +152,29 @@ public class SysDictData extends BaseEntity {
|
||||
this.pyStr = pyStr;
|
||||
}
|
||||
|
||||
public String getDictValueEn() {
|
||||
return dictValueEn;
|
||||
}
|
||||
|
||||
public void setDictValueEn(String dictValueEn) {
|
||||
this.dictValueEn = dictValueEn;
|
||||
}
|
||||
|
||||
public String getDictValueVi() {
|
||||
return dictValueVi;
|
||||
}
|
||||
|
||||
public void setDictValueVi(String dictValueVi) {
|
||||
this.dictValueVi = dictValueVi;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).append("dictCode", getDictCode())
|
||||
.append("dictSort", getDictSort()).append("dictLabel", getDictLabel()).append("dictValue", getDictValue())
|
||||
.append("dictType", getDictType()).append("cssClass", getCssClass()).append("listClass", getListClass())
|
||||
.append("isDefault", getIsDefault()).append("status", getStatus()).append("pyStr", getPyStr())
|
||||
.append("isDefault", getIsDefault()) .append("status", getStatus()).append("pyStr", getPyStr())
|
||||
.append("dictValueEn", getDictValueEn()).append("dictValueVi", getDictValueVi())
|
||||
.append("createBy", getCreateBy()).append("createTime", getCreateTime()).append("updateBy", getUpdateBy())
|
||||
.append("updateTime", getUpdateTime()).append("remark", getRemark()).toString();
|
||||
}
|
||||
|
||||
@@ -12,6 +12,8 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
|
||||
/**
|
||||
* 字典工具类
|
||||
@@ -76,7 +78,7 @@ public class DictUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据字典类型和字典值获取字典标签
|
||||
* 根据字典类型和字典值获取字典标签(支持国际化)
|
||||
*
|
||||
* @param dictType 字典类型
|
||||
* @param dictValue 字典值
|
||||
@@ -89,6 +91,36 @@ public class DictUtils {
|
||||
return getDictLabel(dictType, dictValue, SEPARATOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据字典类型和字典值获取国际化字典标签
|
||||
*
|
||||
* @param dictType 字典类型
|
||||
* @param dictValue 字典值
|
||||
* @return 国际化字典标签
|
||||
*/
|
||||
public static String getDictLabelI18n(String dictType, String dictValue) {
|
||||
if (StringUtils.isEmpty(dictValue)) {
|
||||
return StringUtils.EMPTY;
|
||||
}
|
||||
List<SysDictData> datas = getDictCache(dictType);
|
||||
if (StringUtils.isNull(datas)) {
|
||||
return StringUtils.EMPTY;
|
||||
}
|
||||
Locale locale = LocaleContextHolder.getLocale();
|
||||
String lang = locale.getLanguage();
|
||||
for (SysDictData dict : datas) {
|
||||
if (dictValue.equals(dict.getDictValue())) {
|
||||
if ("en".equals(lang) && dict.getDictValueEn() != null) {
|
||||
return dict.getDictValueEn();
|
||||
} else if ("vi".equals(lang) && dict.getDictValueVi() != null) {
|
||||
return dict.getDictValueVi();
|
||||
}
|
||||
return dict.getDictLabel();
|
||||
}
|
||||
}
|
||||
return StringUtils.EMPTY;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据字典类型和字典标签获取字典值
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user