Skip to content

Commit d695fc7

Browse files
committed
Update I18nEndpoint.java
1 parent 11f8232 commit d695fc7

File tree

1 file changed

+23
-52
lines changed
  • microsphere-i18n-spring-boot/src/main/java/io/microsphere/i18n/spring/boot/actuate

1 file changed

+23
-52
lines changed

microsphere-i18n-spring-boot/src/main/java/io/microsphere/i18n/spring/boot/actuate/I18nEndpoint.java

Lines changed: 23 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -17,48 +17,41 @@
1717
package io.microsphere.i18n.spring.boot.actuate;
1818

1919
import io.microsphere.i18n.AbstractResourceServiceMessageSource;
20-
import io.microsphere.i18n.CompositeServiceMessageSource;
2120
import io.microsphere.i18n.ServiceMessageSource;
2221
import io.microsphere.i18n.spring.DelegatingServiceMessageSource;
23-
import io.microsphere.i18n.spring.beans.factory.ServiceMessageSourceFactoryBean;
2422
import org.springframework.beans.factory.annotation.Autowired;
2523
import org.springframework.beans.factory.annotation.Qualifier;
2624
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
2725
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
2826

29-
import javax.annotation.PostConstruct;
30-
import java.util.Collections;
3127
import java.util.HashMap;
3228
import java.util.List;
33-
import java.util.Locale;
3429
import java.util.Map;
35-
import java.util.Set;
3630

3731
import static io.microsphere.i18n.spring.constants.I18nConstants.SERVICE_MESSAGE_SOURCE_BEAN_NAME;
32+
import static io.microsphere.i18n.util.I18nUtils.findAllServiceMessageSources;
3833
import static java.util.Collections.emptyList;
39-
import static org.springframework.util.CollectionUtils.isEmpty;
4034

4135
/**
4236
* I18n Spring Boot Actuator Endpoint
43-
* <prev>
37+
* <pre>
4438
* {
45-
* "common" : {
46-
* "zh_CN" : {
47-
* "error.a" : "a"
48-
* }
49-
* },
50-
* "test" : {
51-
* "test.i18n_messages_zh_CN.properties" : {
39+
* "test.i18n_messages_zh.properties": {
5240
*
5341
* },
54-
* "META-INF/i18n/test/i18n_messages_en.properties":{
55-
* "test.a" : "test-a"
56-
* "test.hello" : "Hello,{}"
57-
* }
58-
* ...
42+
* "META-INF/i18n/test/i18n_messages_zh_CN.properties": {
43+
* "test.a": "测试-a",
44+
* "test.hello": "您好,{}"
45+
* },
46+
* "META-INF/i18n/test/i18n_messages_en.properties": {
47+
* "test.a": "test-a",
48+
* "test.hello": "Hello,{}"
49+
* },
50+
* "META-INF/i18n/common/i18n_messages_zh_CN.properties": {
51+
* "common.a": "a"
5952
* }
6053
* }
61-
* </prev>
54+
* </pre>
6255
*
6356
* @author <a href="mailto:[email protected]">Mercy</a>
6457
* @since 1.0.0
@@ -80,43 +73,21 @@ public void initServiceMessageSources(ServiceMessageSource serviceMessageSource)
8073
}
8174

8275
@ReadOperation
83-
public Map<String, Object> invoke() {
76+
public Map<String, Map<String, String>> invoke() {
8477
List<ServiceMessageSource> serviceMessageSources = this.serviceMessageSources;
8578
int size = serviceMessageSources.size();
86-
Map<String, Object> result = new HashMap<>(size);
79+
Map<String, Map<String, String>> allLocalizedResourceMessages = new HashMap<>(size);
8780
for (int i = 0; i < size; i++) {
8881
ServiceMessageSource serviceMessageSource = serviceMessageSources.get(i);
89-
if (serviceMessageSource instanceof CompositeServiceMessageSource) {
90-
CompositeServiceMessageSource compositeServiceMessageSource = (CompositeServiceMessageSource) serviceMessageSource;
91-
for (ServiceMessageSource sms : compositeServiceMessageSource.getServiceMessageSources()) {
92-
if (sms instanceof AbstractResourceServiceMessageSource) {
93-
AbstractResourceServiceMessageSource resourceServiceMessageSource = (AbstractResourceServiceMessageSource) sms;
94-
String source = serviceMessageSource.getSource();
95-
List<Locale> supportedLocales = resourceServiceMessageSource.getSupportedLocales();
96-
Map<String, Map<String, String>> localizedMessages = new HashMap<>(supportedLocales.size());
97-
98-
99-
for (Locale supportedLocale : supportedLocales) {
100-
Map<String, String> messages = resourceServiceMessageSource.getMessages(supportedLocale);
101-
if (!isEmpty(messages)) {
102-
localizedMessages.put(supportedLocale.toString(), messages);
103-
}
104-
}
105-
106-
result.put(source, localizedMessages);
107-
}
82+
List<ServiceMessageSource> subServiceMessageSources = findAllServiceMessageSources(serviceMessageSource);
83+
for (ServiceMessageSource subServiceMessageSource : subServiceMessageSources) {
84+
if (subServiceMessageSource instanceof AbstractResourceServiceMessageSource) {
85+
AbstractResourceServiceMessageSource resourceServiceMessageSource = (AbstractResourceServiceMessageSource) subServiceMessageSource;
86+
Map<String, Map<String, String>> localizedResourceMessages = resourceServiceMessageSource.getLocalizedResourceMessages();
87+
allLocalizedResourceMessages.putAll(localizedResourceMessages);
10888
}
10989
}
110-
111-
}
112-
return result;
113-
}
114-
115-
private AbstractResourceServiceMessageSource getResourceServiceMessageSource(ServiceMessageSource serviceMessageSource) {
116-
if (serviceMessageSource instanceof ServiceMessageSourceFactoryBean) {
117-
ServiceMessageSourceFactoryBean smffb = (ServiceMessageSourceFactoryBean) serviceMessageSource;
118-
CompositeServiceMessageSource compositeServiceMessageSource = smffb.getDelegate();
11990
}
120-
return null;
91+
return allLocalizedResourceMessages;
12192
}
12293
}

0 commit comments

Comments
 (0)