Skip to content

Commit 711150d

Browse files
committed
refactor: 优化I18nSupportUtils
1 parent 99aafcf commit 711150d

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

hsweb-core/src/main/java/org/hswebframework/web/i18n/I18nSupportUtils.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,42 @@ public static Map<String, Map<String, String>> putI18nMessages(String i18nKey,
1414
String property,
1515
Collection<Locale> locales,
1616
String defaultMsg,
17-
Map<String, Map<String, String>> container) {
17+
Map<String, Map<String, String>> container,
18+
Object... args) {
1819
if (container == null) {
1920
container = new HashMap<>();
2021
}
2122

2223
container.compute(
2324
property,
2425
(p, c) -> {
25-
Map<String, String> msg = putI18nMessages(i18nKey, locales, defaultMsg, c);
26+
Map<String, String> msg = putI18nMessages(i18nKey, locales, defaultMsg, c, args);
2627
//为空不存储
2728
return MapUtils.isEmpty(msg) ? null : msg;
2829
});
2930

3031
return container;
3132
}
3233

34+
public static Map<String, Map<String, String>> putI18nMessages(String i18nKey,
35+
String property,
36+
Collection<Locale> locales,
37+
String defaultMsg,
38+
Map<String, Map<String, String>> container) {
39+
return putI18nMessages(i18nKey, property, locales, defaultMsg, container, new Object[0]);
40+
}
41+
3342
public static Map<String, String> putI18nMessages(String i18nKey,
3443
Collection<Locale> locales,
3544
String defaultMsg,
36-
Map<String, String> container) {
45+
Map<String, String> container,
46+
Object... args) {
3747
if (container == null) {
3848
container = new HashMap<>();
3949
}
4050

4151
for (Locale locale : locales) {
42-
String msg = LocaleUtils.resolveMessage(i18nKey, locale, defaultMsg);
52+
String msg = LocaleUtils.resolveMessage(i18nKey, locale, defaultMsg, args);
4353
if (StringUtils.hasText(msg)) {
4454
container.put(locale.toString(), msg);
4555
}
@@ -49,4 +59,12 @@ public static Map<String, String> putI18nMessages(String i18nKey,
4959
}
5060

5161

62+
public static Map<String, String> putI18nMessages(String i18nKey,
63+
Collection<Locale> locales,
64+
String defaultMsg,
65+
Map<String, String> container) {
66+
return putI18nMessages(i18nKey, locales, defaultMsg, container, new Object[0]);
67+
}
68+
69+
5270
}

0 commit comments

Comments
 (0)