Browse Source

优化i18n文件加载优化逻辑

zhou-hao 3 years ago
parent
commit
c0a863c430

+ 9 - 5
hsweb-starter/src/main/java/org/hswebframework/web/starter/i18n/I18nConfiguration.java

@@ -15,6 +15,7 @@ import org.springframework.core.io.Resource;
 import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
 import org.springframework.util.StringUtils;
 
+import java.util.Arrays;
 import java.util.stream.Collectors;
 
 @Configuration(proxyBeanMethods = false)
@@ -33,11 +34,14 @@ public class I18nConfiguration {
         for (Resource resource : resources) {
             String path = resource.getURL().getPath();
             if (StringUtils.hasText(path) && (path.endsWith(".properties") || path.endsWith(".xml"))) {
-                String name = path.substring(path.lastIndexOf("i18n"),path.indexOf("_"));
-
-                log.info("register i18n message resource {} -> {}", path,name);
-
-                messageSource.addBasenames(name);
+                path = path.substring(path.lastIndexOf("i18n"));
+                String[] split = path.split("[/|\\\\]");
+                String name = split[split.length - 1];
+                name = name.contains("_") ? name.substring(0, name.indexOf("_")) : name;
+                split[split.length - 1] = name;
+                log.info("register i18n message resource {} -> {}", path, name);
+
+                messageSource.addBasenames(String.join("/", split));
             }
         }
         return messageSource;