17
17
package io .microsphere .i18n .spring .boot .actuate ;
18
18
19
19
import io .microsphere .i18n .AbstractResourceServiceMessageSource ;
20
- import io .microsphere .i18n .CompositeServiceMessageSource ;
21
20
import io .microsphere .i18n .ServiceMessageSource ;
22
21
import io .microsphere .i18n .spring .DelegatingServiceMessageSource ;
23
- import io .microsphere .i18n .spring .beans .factory .ServiceMessageSourceFactoryBean ;
24
22
import org .springframework .beans .factory .annotation .Autowired ;
25
23
import org .springframework .beans .factory .annotation .Qualifier ;
26
24
import org .springframework .boot .actuate .endpoint .annotation .Endpoint ;
27
25
import org .springframework .boot .actuate .endpoint .annotation .ReadOperation ;
28
26
29
- import javax .annotation .PostConstruct ;
30
- import java .util .Collections ;
31
27
import java .util .HashMap ;
32
28
import java .util .List ;
33
- import java .util .Locale ;
34
29
import java .util .Map ;
35
- import java .util .Set ;
36
30
37
31
import static io .microsphere .i18n .spring .constants .I18nConstants .SERVICE_MESSAGE_SOURCE_BEAN_NAME ;
32
+ import static io .microsphere .i18n .util .I18nUtils .findAllServiceMessageSources ;
38
33
import static java .util .Collections .emptyList ;
39
- import static org .springframework .util .CollectionUtils .isEmpty ;
40
34
41
35
/**
42
36
* I18n Spring Boot Actuator Endpoint
43
- * <prev >
37
+ * <pre >
44
38
* {
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": {
52
40
*
53
41
* },
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"
59
52
* }
60
53
* }
61
- * </prev >
54
+ * </pre >
62
55
*
63
56
* @author <a href="mailto:[email protected] ">Mercy</a>
64
57
* @since 1.0.0
@@ -80,43 +73,21 @@ public void initServiceMessageSources(ServiceMessageSource serviceMessageSource)
80
73
}
81
74
82
75
@ ReadOperation
83
- public Map <String , Object > invoke () {
76
+ public Map <String , Map < String , String > > invoke () {
84
77
List <ServiceMessageSource > serviceMessageSources = this .serviceMessageSources ;
85
78
int size = serviceMessageSources .size ();
86
- Map <String , Object > result = new HashMap <>(size );
79
+ Map <String , Map < String , String >> allLocalizedResourceMessages = new HashMap <>(size );
87
80
for (int i = 0 ; i < size ; i ++) {
88
81
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 );
108
88
}
109
89
}
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 ();
119
90
}
120
- return null ;
91
+ return allLocalizedResourceMessages ;
121
92
}
122
93
}
0 commit comments