mirror of
https://gitee.com/fit2cloud-feizhiyun/MeterSphere.git
synced 2024-11-30 02:58:31 +08:00
refactor: 增加指定语言方法用于定时任务或后端发送消息时使用
This commit is contained in:
parent
d1122b8958
commit
bc1455314c
@ -4,6 +4,8 @@ import jakarta.annotation.Resource;
|
||||
import org.springframework.context.MessageSource;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class Translator {
|
||||
private static MessageSource messageSource;
|
||||
|
||||
@ -26,10 +28,19 @@ public class Translator {
|
||||
return messageSource.getMessage(key, null, defaultMessage, LocaleContextHolder.getLocale());
|
||||
}
|
||||
|
||||
/**
|
||||
* 单Key翻译,并指定默认语言
|
||||
*/
|
||||
public static String get(String key, Locale locale) {
|
||||
return messageSource.getMessage(key, null, locale);
|
||||
}
|
||||
|
||||
/**
|
||||
* 带参数
|
||||
*/
|
||||
public static String getWithArgs(String key, Object... args) {
|
||||
return messageSource.getMessage(key, args, "Not Support Key: " + key, LocaleContextHolder.getLocale());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user