Search in sources :

Example 1 with LocaleProperties

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;
}
Also used : PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) Resource(org.springframework.core.io.Resource) ResourceBundleMessageSource(org.springframework.context.support.ResourceBundleMessageSource) LocaleProperties(org.smartframework.cloud.starter.configure.properties.LocaleProperties) IOException(java.io.IOException) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) Bean(org.springframework.context.annotation.Bean)

Aggregations

IOException (java.io.IOException)1 LocaleProperties (org.smartframework.cloud.starter.configure.properties.LocaleProperties)1 Bean (org.springframework.context.annotation.Bean)1 ResourceBundleMessageSource (org.springframework.context.support.ResourceBundleMessageSource)1 Resource (org.springframework.core.io.Resource)1 PathMatchingResourcePatternResolver (org.springframework.core.io.support.PathMatchingResourcePatternResolver)1 ResourcePatternResolver (org.springframework.core.io.support.ResourcePatternResolver)1