add CutEnum 重命名为 LanguageEnum
This commit is contained in:
-37
@@ -1,37 +0,0 @@
|
||||
package com.jero.common.constant.enums;
|
||||
|
||||
/**
|
||||
* 中英文切换标识
|
||||
* @description
|
||||
* @date 2022/1/21 15:22
|
||||
* @auth zhn
|
||||
*/
|
||||
public enum CutEnum {
|
||||
CN("中文","cn"),
|
||||
EN("英文","en");
|
||||
|
||||
|
||||
String name;
|
||||
String value;
|
||||
|
||||
private CutEnum(String name, String value) {
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package com.jero.common.constant.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 中英文切换标识
|
||||
* @description
|
||||
* @date 2022/1/21 15:22
|
||||
* @auth zhn
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum LanguageEnum {
|
||||
/**
|
||||
* 中文,英文
|
||||
*/
|
||||
CN("cn"), EN("en");
|
||||
|
||||
String value;
|
||||
|
||||
}
|
||||
+8
-1
@@ -1,6 +1,7 @@
|
||||
package com.jero.common.util;
|
||||
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import com.jero.common.constant.enums.LanguageEnum;
|
||||
import org.springframework.context.MessageSource;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
|
||||
@@ -15,8 +16,14 @@ public class MessageUtils {
|
||||
* @param args 参数
|
||||
* @return 获取国际化翻译值
|
||||
*/
|
||||
public static String message(String code, Object... args) {
|
||||
public static String getMessage(String code, Object... args) {
|
||||
MessageSource messageSource = SpringUtil.getBean(MessageSource.class);
|
||||
return messageSource.getMessage(code, args, LocaleContextHolder.getLocale());
|
||||
}
|
||||
|
||||
public static LanguageEnum getLanguage() {
|
||||
String language = LocaleContextHolder.getLocale().getLanguage();
|
||||
|
||||
return LanguageEnum.EN.getValue().equals(language) ? LanguageEnum.EN : LanguageEnum.CN;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user