123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- package com.boman.system.common;
- /**
- * @author shiqian
- * @description
- * @date 2021年03月22日 13:54
- **/
- import java.util.HashMap;
- import java.util.Locale;
- import java.util.Map;
- import java.util.ResourceBundle;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.context.annotation.PropertySource;
- @PropertySource(
- value = {"classpath:application.properties", "classpath:config/email.properties", "classpath:config/thirdParty.properties", "classpath:config/ebossCloud.properties", "classpath:i18n/messages*.properties"},
- ignoreResourceNotFound = true
- )
- public final class Resources {
- private static final Logger log = LoggerFactory.getLogger(Resources.class);
- private static final Map<String, ResourceBundle> MESSAGES = new HashMap();
- public Resources() {
- }
- public static String getMessage(String key, Object... params) {
- return getMessage(key, (Locale)null, params);
- }
- public static String getMessage(String key, Locale plocale, Object... params) {
- ResourceBundle pp = ResourceBundle.getBundle("application");
- String defaultLocal = pp.getString("spring.locale.default");
- // Locale locale = plocale != null ? plocale : Tools.getLocale("zh_CN");
- Locale locale = Locale.getDefault();
- ResourceBundle message = (ResourceBundle)MESSAGES.get(locale.getLanguage());
- if (message == null) {
- synchronized(MESSAGES) {
- message = (ResourceBundle)MESSAGES.get(locale.getLanguage());
- if (message == null) {
- message = ResourceBundle.getBundle("i18n/messages", locale);
- MESSAGES.put(locale.getLanguage(), message);
- }
- }
- }
- try {
- return params != null ? String.format(message.getString(key), params) : message.getString(key);
- } catch (Exception var10) {
- return locale.toString().equals(defaultLocal) && params.length == 1 ? String.valueOf(params[0]) : key;
- }
- }
- public static void flushMessage() {
- MESSAGES.clear();
- }
- }
|