Skip to content

Commit 62269ee

Browse files
committed
feat(i18n): Allow not to use i18n feature
1 parent d3bdc58 commit 62269ee

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed
Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
11
package com.github.codeboyzhou.mcp.declarative.server.factory;
22

33
import com.google.inject.Injector;
4+
import org.slf4j.Logger;
5+
import org.slf4j.LoggerFactory;
46

57
import java.util.Locale;
68
import java.util.ResourceBundle;
79

810
public 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
}

src/test/resources/i18n/mcp_server_component_descriptions.properties

Whitespace-only changes.

0 commit comments

Comments
 (0)