Skip to content

Commit

Permalink
fix: 修复 k8s 环境下无法加载翻译文件的 bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron3S committed Jul 10, 2024
1 parent 2847de8 commit c8cf748
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.AbstractMessageSource;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
Expand Down Expand Up @@ -63,7 +63,14 @@ class JsonMessageSource extends AbstractMessageSource {


public JsonMessageSource(@Value("${i18n.endpoint}") String endpoint) {
this.endpoint = endpoint;
// 首先从环境变量中读取 core 的地址

String coreHost = System.getenv("CORE_HOST");
if (StringUtils.isNotBlank(coreHost)) {
this.endpoint = coreHost;
} else {
this.endpoint = endpoint;
}

var languages = new String[]{
"en", "ja", "zh", "zh_hant"
Expand Down Expand Up @@ -128,7 +135,7 @@ protected MessageFormat resolveCode(String code, Locale locale) {
Map<String, String> localeMessages = messages.get(languageTag);
if (localeMessages != null) {
String message = localeMessages.get(code);
if (StringUtils.hasText(message)) {
if (StringUtils.isNoneBlank(message)) {
return new MessageFormat(message, locale);
}
}
Expand Down

0 comments on commit c8cf748

Please sign in to comment.