use of org.smartframework.cloud.starter.configure.properties.LocaleProperties in project smart-cloud by smart-cloud.
the class LocaleAutoConfiguration method messageSource.
@Bean
public MessageSource messageSource(final SmartProperties smartProperties) {
LocaleProperties localeProperties = smartProperties.getLocale();
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
Resource[] resources = null;
try {
resources = resolver.getResources(LocaleConstant.LOCALE_PATTERN);
} catch (IOException e) {
log.error(e.getMessage(), e);
}
ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
if (resources != null) {
String[] strResources = new String[resources.length];
for (int i = 0; i < resources.length; i++) {
Resource resource = resources[i];
strResources[i] = LocaleConstant.LOCALE_DIR + resource.getFilename().replace(LocaleConstant.LOCALE_PROPERTIES_SUFFIX, "");
}
messageSource.setBasenames(strResources);
}
messageSource.setDefaultEncoding(localeProperties.getEncoding());
messageSource.setCacheSeconds(localeProperties.getCacheSeconds());
return messageSource;
}
Aggregations