|
3 | 3 | import com.fasterxml.jackson.core.type.TypeReference;
|
4 | 4 | import com.fasterxml.jackson.databind.ObjectMapper;
|
5 | 5 | import lombok.extern.slf4j.Slf4j;
|
| 6 | +import org.apache.commons.lang3.StringUtils; |
6 | 7 | import org.springframework.beans.factory.annotation.Value;
|
7 | 8 | import org.springframework.context.MessageSource;
|
8 | 9 | import org.springframework.context.annotation.Bean;
|
9 | 10 | import org.springframework.context.annotation.Configuration;
|
10 | 11 | import org.springframework.context.support.AbstractMessageSource;
|
11 | 12 | import org.springframework.stereotype.Component;
|
12 |
| -import org.springframework.util.StringUtils; |
13 | 13 | import org.springframework.web.client.RestTemplate;
|
14 | 14 | import org.springframework.web.servlet.LocaleResolver;
|
15 | 15 | import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
@@ -63,7 +63,14 @@ class JsonMessageSource extends AbstractMessageSource {
|
63 | 63 |
|
64 | 64 |
|
65 | 65 | public JsonMessageSource(@Value("${i18n.endpoint}") String endpoint) {
|
66 |
| - this.endpoint = endpoint; |
| 66 | + // 首先从环境变量中读取 core 的地址 |
| 67 | + |
| 68 | + String coreHost = System.getenv("CORE_HOST"); |
| 69 | + if (StringUtils.isNotBlank(coreHost)) { |
| 70 | + this.endpoint = coreHost; |
| 71 | + } else { |
| 72 | + this.endpoint = endpoint; |
| 73 | + } |
67 | 74 |
|
68 | 75 | var languages = new String[]{
|
69 | 76 | "en", "ja", "zh", "zh_hant"
|
@@ -128,7 +135,7 @@ protected MessageFormat resolveCode(String code, Locale locale) {
|
128 | 135 | Map<String, String> localeMessages = messages.get(languageTag);
|
129 | 136 | if (localeMessages != null) {
|
130 | 137 | String message = localeMessages.get(code);
|
131 |
| - if (StringUtils.hasText(message)) { |
| 138 | + if (StringUtils.isNoneBlank(message)) { |
132 | 139 | return new MessageFormat(message, locale);
|
133 | 140 | }
|
134 | 141 | }
|
|
0 commit comments