1
1
package com .github .codeboyzhou .mcp .declarative .server .factory ;
2
2
3
3
import com .google .inject .Injector ;
4
+ import org .slf4j .Logger ;
5
+ import org .slf4j .LoggerFactory ;
4
6
5
7
import java .util .Locale ;
6
8
import java .util .ResourceBundle ;
7
9
8
10
public abstract class AbstractMcpServerComponentFactory <T > implements McpServerComponentFactory <T > {
9
11
12
+ private static final Logger logger = LoggerFactory .getLogger (AbstractMcpServerComponentFactory .class );
13
+
14
+ private static final String RESOURCE_BUNDLE_BASE_NAME = "i18n/mcp_server_component_descriptions" ;
15
+
10
16
protected final Injector injector ;
11
17
12
18
private final ResourceBundle bundle ;
13
19
14
20
protected AbstractMcpServerComponentFactory (Injector injector ) {
15
21
this .injector = injector ;
16
- this .bundle = ResourceBundle . getBundle ( "i18n/mcp_server_component_descriptions" , Locale . getDefault () );
22
+ this .bundle = loadResourceBundle ( );
17
23
}
18
24
19
25
protected String getDescription (String descriptionI18nKey , String description ) {
20
- if (!descriptionI18nKey .isBlank () && bundle .containsKey (descriptionI18nKey )) {
26
+ if (!descriptionI18nKey .isBlank () && bundle != null && bundle .containsKey (descriptionI18nKey )) {
21
27
return bundle .getString (descriptionI18nKey );
22
28
}
23
29
if (!description .isBlank ()) {
@@ -26,4 +32,14 @@ protected String getDescription(String descriptionI18nKey, String description) {
26
32
return "No description provided." ;
27
33
}
28
34
35
+ private ResourceBundle loadResourceBundle () {
36
+ Locale locale = Locale .getDefault ();
37
+ try {
38
+ return ResourceBundle .getBundle (RESOURCE_BUNDLE_BASE_NAME , locale );
39
+ } catch (Exception e ) {
40
+ logger .warn ("Can't find resource bundle for base name: {}, locale {}, i18n will be unsupported" , RESOURCE_BUNDLE_BASE_NAME , locale );
41
+ return null ;
42
+ }
43
+ }
44
+
29
45
}
0 commit comments