11package com .github .codeboyzhou .mcp .declarative .server .factory ;
22
33import com .google .inject .Injector ;
4+ import org .slf4j .Logger ;
5+ import org .slf4j .LoggerFactory ;
46
57import java .util .Locale ;
68import java .util .ResourceBundle ;
79
810public abstract class AbstractMcpServerComponentFactory <T > implements McpServerComponentFactory <T > {
911
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+
1016 protected final Injector injector ;
1117
1218 private final ResourceBundle bundle ;
1319
1420 protected AbstractMcpServerComponentFactory (Injector injector ) {
1521 this .injector = injector ;
16- this .bundle = ResourceBundle . getBundle ( "i18n/mcp_server_component_descriptions" , Locale . getDefault () );
22+ this .bundle = loadResourceBundle ( );
1723 }
1824
1925 protected String getDescription (String descriptionI18nKey , String description ) {
20- if (!descriptionI18nKey .isBlank () && bundle .containsKey (descriptionI18nKey )) {
26+ if (!descriptionI18nKey .isBlank () && bundle != null && bundle .containsKey (descriptionI18nKey )) {
2127 return bundle .getString (descriptionI18nKey );
2228 }
2329 if (!description .isBlank ()) {
@@ -26,4 +32,14 @@ protected String getDescription(String descriptionI18nKey, String description) {
2632 return "No description provided." ;
2733 }
2834
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+
2945}
0 commit comments