update 使用全局国际化过滤器 GlobalI18nFilter 优化 Gateway 国际化处理

This commit is contained in:
疯狂的狮子li
2022-06-02 16:43:14 +08:00
parent e1c789b947
commit d3ded4162e
4 changed files with 47 additions and 54 deletions

View File

@@ -3,6 +3,7 @@ package com.ruoyi.common.core.utils;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.springframework.context.MessageSource;
import org.springframework.context.NoSuchMessageException;
import org.springframework.context.i18n.LocaleContextHolder;
/**
@@ -23,6 +24,10 @@ public class MessageUtils {
* @return 获取国际化翻译值
*/
public static String message(String code, Object... args) {
return MESSAGE_SOURCE.getMessage(code, args, LocaleContextHolder.getLocale());
try {
return MESSAGE_SOURCE.getMessage(code, args, LocaleContextHolder.getLocale());
} catch (NoSuchMessageException e) {
return code;
}
}
}