Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit cc764ec

Browse files
committedJul 10, 2024·
fix: 修复 k8s 环境下无法加载翻译文件的 bug
1 parent fb1aabe commit cc764ec

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed
 

‎backend/web/src/main/java/org/jumpserver/chen/web/config/LocaleConfig.java

+10-3
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
import com.fasterxml.jackson.core.type.TypeReference;
44
import com.fasterxml.jackson.databind.ObjectMapper;
55
import lombok.extern.slf4j.Slf4j;
6+
import org.apache.commons.lang3.StringUtils;
67
import org.springframework.beans.factory.annotation.Value;
78
import org.springframework.context.MessageSource;
89
import org.springframework.context.annotation.Bean;
910
import org.springframework.context.annotation.Configuration;
1011
import org.springframework.context.support.AbstractMessageSource;
1112
import org.springframework.stereotype.Component;
12-
import org.springframework.util.StringUtils;
1313
import org.springframework.web.client.RestTemplate;
1414
import org.springframework.web.servlet.LocaleResolver;
1515
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
@@ -63,7 +63,14 @@ class JsonMessageSource extends AbstractMessageSource {
6363

6464

6565
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+
}
6774

6875
var languages = new String[]{
6976
"en", "ja", "zh", "zh_hant"
@@ -128,7 +135,7 @@ protected MessageFormat resolveCode(String code, Locale locale) {
128135
Map<String, String> localeMessages = messages.get(languageTag);
129136
if (localeMessages != null) {
130137
String message = localeMessages.get(code);
131-
if (StringUtils.hasText(message)) {
138+
if (StringUtils.isNoneBlank(message)) {
132139
return new MessageFormat(message, locale);
133140
}
134141
}

0 commit comments

Comments
 (0)
Please sign in to comment.