Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 修复 k8s 环境下无法加载翻译文件的 bug #10

Merged
merged 1 commit into from
Jul 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.isNotBlank(message)) {
return new MessageFormat(message, locale);
}
}
Expand Down