Java Code Examples for org.springframework.context.support.ResourceBundleMessageSource#setBasenames()

The following examples show how to use org.springframework.context.support.ResourceBundleMessageSource#setBasenames() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MessageImpl.java    From tephra with MIT License 6 votes vote down vote up
@Override
public void onContextRefreshed() {
    Set<String> messages = new HashSet<>();
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    for (String beanName : BeanFactory.getBeanNames()) {
        Package beanPackage = BeanFactory.getBeanClass(beanName).getPackage();
        if (beanPackage == null) {
            logger.warn(null, "无法获得Bean[{}]包。", beanName);

            continue;
        }

        String packageName = beanPackage.getName();
        if (resolver.getResource(packageName.replace('.', File.separatorChar) + "/message.properties").exists())
            messages.add(packageName);
    }

    String[] names = new String[messages.size()];
    int i = 0;
    for (String name : messages)
        names[i++] = name + ".message";
    messageSource = new ResourceBundleMessageSource();
    messageSource.setDefaultEncoding(context.getCharset(null));
    messageSource.setBasenames(names);
}
 
Example 2
Source File: MessageResourceExtension.java    From Spring-Boot-I18n-Pro with MIT License 6 votes vote down vote up
@PostConstruct
public void init() {
    logger.info("init MessageResourceExtension...");
    if (!StringUtils.isEmpty(baseFolder)) {
        try {
            this.setBasenames(getAllBaseNames(baseFolder));
        } catch (IOException e) {
            logger.error(e.getMessage());
        }
    }
    //设置父MessageSource
    ResourceBundleMessageSource parent = new ResourceBundleMessageSource();
    //是否是多个目录
    if (basename.indexOf(",") > 0) {
        parent.setBasenames(basename.split(","));
    } else {
        parent.setBasename(basename);
    }
    //设置文件编码
    parent.setDefaultEncoding("UTF-8");
    this.setParentMessageSource(parent);
}
 
Example 3
Source File: DefaultValuesControllerTest.java    From n2o-framework with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() {
    N2oEnvironment environment = new N2oEnvironment();
    environment.setNamespacePersisterFactory(new PersisterFactoryByMap());
    environment.setNamespaceReaderFactory(new ReaderFactoryByMap());
    ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
    messageSource.setBasenames("n2o_messages", "messages");
    messageSource.setDefaultEncoding("UTF-8");
    environment.setMessageSource(new MessageSourceAccessor(messageSource));
    OverrideProperties properties = PropertiesReader.getPropertiesFromClasspath("META-INF/n2o.properties");
    properties.put("n2o.engine.mapper", "spel");
    environment.setSystemProperties(new SimplePropertyResolver(properties));
    builder = new N2oApplicationBuilder(environment);
    configure(builder);
    CompileInfo.setSourceTypes(builder.getEnvironment().getSourceTypeRegister());
}
 
Example 4
Source File: CopyValuesControllerTest.java    From n2o-framework with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() {
    N2oEnvironment environment = new N2oEnvironment();
    environment.setNamespacePersisterFactory(new PersisterFactoryByMap());
    environment.setNamespaceReaderFactory(new ReaderFactoryByMap());
    ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
    messageSource.setBasenames("n2o_messages", "messages");
    messageSource.setDefaultEncoding("UTF-8");
    environment.setMessageSource(new MessageSourceAccessor(messageSource));
    OverrideProperties properties = PropertiesReader.getPropertiesFromClasspath("META-INF/n2o.properties");
    properties.put("n2o.engine.mapper", "spel");
    environment.setSystemProperties(new SimplePropertyResolver(properties));
    builder = new N2oApplicationBuilder(environment);
    configure(builder);
    CompileInfo.setSourceTypes(builder.getEnvironment().getSourceTypeRegister());
}
 
Example 5
Source File: ApplicationConfig.java    From ZTuoExchange_framework with MIT License 5 votes vote down vote up
@Bean(name = "messageSource")
public ResourceBundleMessageSource getMessageSource() {
    ResourceBundleMessageSource resourceBundleMessageSource = new ResourceBundleMessageSource();
    resourceBundleMessageSource.setDefaultEncoding("UTF-8");
    resourceBundleMessageSource.setBasenames("i18n/messages", "i18n/ValidationMessages");
    resourceBundleMessageSource.setCacheSeconds(3600);
    return resourceBundleMessageSource;
}
 
Example 6
Source File: MvcConfig.java    From mywx with Apache License 2.0 5 votes vote down vote up
@Bean
public ResourceBundleMessageSource messageSource() {
    ResourceBundleMessageSource source = new ResourceBundleMessageSource();
    source.setBasenames("i18n/message");
    source.setUseCodeAsDefaultMessage(true);
    return source;
}
 
Example 7
Source File: I18nConfiguration.java    From java-platform with Apache License 2.0 5 votes vote down vote up
@Bean
public ResourceBundleMessageSource messageSource() {
	ResourceBundleMessageSource bundleMessageSource = new ResourceBundleMessageSource();
	bundleMessageSource.setUseCodeAsDefaultMessage(true);
	bundleMessageSource.setBasenames(i18nMessages.split(","));
	return bundleMessageSource;
}
 
Example 8
Source File: ClientWebConfigJava.java    From tutorials with MIT License 5 votes vote down vote up
@Bean
public MessageSource messageSource() {

    final ResourceBundleMessageSource ms = new ResourceBundleMessageSource();
    ms.setBasenames("messages");
    return ms;
}
 
Example 9
Source File: LocalizationConfiguration.java    From spring-rdbms-cdc-kafka-elasticsearch with Apache License 2.0 5 votes vote down vote up
/**
 * Set the source of i18n messages under "resources/i18n/messages_[locale].properties"
 *
 * @return instance of {@link ResourceBundleMessageSource}
 */
@Bean
public ResourceBundleMessageSource messageSource() {
  ResourceBundleMessageSource source = new ResourceBundleMessageSource();
  source.setBasenames("i18n/messages");
  source.setUseCodeAsDefaultMessage(true);
  return source;
}
 
Example 10
Source File: LocalizationConfiguration.java    From spring-rdbms-cdc-kafka-elasticsearch with Apache License 2.0 5 votes vote down vote up
/**
 * Set the source of i18n messages under "resources/i18n/messages_[locale].properties"
 *
 * @return instance of {@link ResourceBundleMessageSource}
 */
@Bean
public ResourceBundleMessageSource messageSource() {
  ResourceBundleMessageSource source = new ResourceBundleMessageSource();
  source.setBasenames("i18n/messages");
  source.setUseCodeAsDefaultMessage(true);
  return source;
}
 
Example 11
Source File: N2oTestBase.java    From n2o-framework with Apache License 2.0 5 votes vote down vote up
public void setUp() throws Exception {
    N2oEnvironment environment = new N2oEnvironment();
    environment.setNamespacePersisterFactory(new PersisterFactoryByMap());
    environment.setNamespaceReaderFactory(new ReaderFactoryByMap());
    ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
    messageSource.setBasenames("n2o_messages", "messages");
    messageSource.setDefaultEncoding("UTF-8");
    environment.setMessageSource(new MessageSourceAccessor(messageSource));
    OverrideProperties properties = PropertiesReader.getPropertiesFromClasspath("META-INF/n2o.properties");
    environment.setSystemProperties(new SimplePropertyResolver(properties));

    builder = new N2oApplicationBuilder(environment);
    configure(builder);
    CompileInfo.setSourceTypes(builder.getEnvironment().getSourceTypeRegister());
}
 
Example 12
Source File: N2oMessagesConfiguration.java    From n2o-framework with Apache License 2.0 5 votes vote down vote up
@Bean("n2oMessageSource")
@ConditionalOnMissingBean(name = "n2oMessageSource")
public MessageSource n2oMessageSource() {
    ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
    messageSource.setDefaultEncoding(encoding.name());
    messageSource.setCacheSeconds(cacheSeconds);
    messageSource.setBasenames(StringUtils.commaDelimitedListToStringArray(
            StringUtils.trimAllWhitespace(basename)));
    messageSource.addBasenames("n2o_messages", "n2o_content");
    return messageSource;
}
 
Example 13
Source File: ApplicationConfig.java    From ZTuoExchange_framework with MIT License 5 votes vote down vote up
/**
 * 国际化
 *
 * @return
 */
@Bean(name = "messageSource")
public ResourceBundleMessageSource getMessageSource() {
    ResourceBundleMessageSource resourceBundleMessageSource = new ResourceBundleMessageSource();
    resourceBundleMessageSource.setDefaultEncoding("UTF-8");
    resourceBundleMessageSource.setBasenames("i18n/messages", "i18n/ValidationMessages");
    resourceBundleMessageSource.setCacheSeconds(3600);
    return resourceBundleMessageSource;
}
 
Example 14
Source File: ApplicationConfig.java    From ZTuoExchange_framework with MIT License 5 votes vote down vote up
/**
 * 此处有很多坑,不一一叙述,如无必要,不要更改
 *
 * @return
 */
@Bean(name = "messageSource")
public ResourceBundleMessageSource getMessageSource() {
    ResourceBundleMessageSource resourceBundleMessageSource = new ResourceBundleMessageSource();
    resourceBundleMessageSource.setDefaultEncoding("UTF-8");
    resourceBundleMessageSource.setBasenames("i18n/messages", "i18n/ValidationMessages");
    resourceBundleMessageSource.setCacheSeconds(3600);
    return resourceBundleMessageSource;
}
 
Example 15
Source File: ApplicationConfig.java    From ZTuoExchange_framework with MIT License 5 votes vote down vote up
@Bean(name = "messageSource")
public ResourceBundleMessageSource getMessageSource() {
    ResourceBundleMessageSource resourceBundleMessageSource = new ResourceBundleMessageSource();
    resourceBundleMessageSource.setDefaultEncoding("UTF-8");
    resourceBundleMessageSource.setBasenames("i18n/messages", "i18n/ValidationMessages");
    resourceBundleMessageSource.setCacheSeconds(3600);
    return resourceBundleMessageSource;
}
 
Example 16
Source File: ApplicationConfig.java    From ZTuoExchange_framework with MIT License 5 votes vote down vote up
/**
 * 国际化
 *
 * @return
 */
@Bean(name = "messageSource")
public ResourceBundleMessageSource getMessageSource() {
    ResourceBundleMessageSource resourceBundleMessageSource = new ResourceBundleMessageSource();
    resourceBundleMessageSource.setDefaultEncoding("UTF-8");
    resourceBundleMessageSource.setBasenames("i18n/messages", "i18n/ValidationMessages");
    resourceBundleMessageSource.setCacheSeconds(3600);
    return resourceBundleMessageSource;
}
 
Example 17
Source File: ApplicationConfig.java    From ZTuoExchange_framework with MIT License 5 votes vote down vote up
/**
 * 国际化
 *
 * @return
 */
@Bean(name = "messageSource")
public ResourceBundleMessageSource getMessageSource() {
    ResourceBundleMessageSource resourceBundleMessageSource = new ResourceBundleMessageSource();
    resourceBundleMessageSource.setDefaultEncoding("UTF-8");
    resourceBundleMessageSource.setBasenames("i18n/messages", "i18n/ValidationMessages");
    resourceBundleMessageSource.setCacheSeconds(3600);
    return resourceBundleMessageSource;
}
 
Example 18
Source File: ApplicationConfig.java    From ZTuoExchange_framework with MIT License 5 votes vote down vote up
/**
 * 此处有很多坑,不一一叙述,如无必要,不要更改
 *
 * @return
 */
@Bean(name = "messageSource")
public ResourceBundleMessageSource getMessageSource() {
    ResourceBundleMessageSource resourceBundleMessageSource = new ResourceBundleMessageSource();
    resourceBundleMessageSource.setDefaultEncoding("UTF-8");
    resourceBundleMessageSource.setBasenames("i18n/messages", "i18n/ValidationMessages");
    resourceBundleMessageSource.setCacheSeconds(3600);
    return resourceBundleMessageSource;
}
 
Example 19
Source File: ApplicationConfig.java    From ZTuoExchange_framework with MIT License 5 votes vote down vote up
/**
 * 国际化
 *
 * @return
 */
@Bean(name = "messageSource")
public ResourceBundleMessageSource getMessageSource() {
    ResourceBundleMessageSource resourceBundleMessageSource = new ResourceBundleMessageSource();
    resourceBundleMessageSource.setDefaultEncoding("UTF-8");
    resourceBundleMessageSource.setBasenames("i18n/messages", "i18n/ValidationMessages");
    resourceBundleMessageSource.setCacheSeconds(3600);
    return resourceBundleMessageSource;
}
 
Example 20
Source File: SpringBundle.java    From data-prep with Apache License 2.0 4 votes vote down vote up
protected SpringBundle(String... baseNames) {
    source = new ResourceBundleMessageSource();
    source.setFallbackToSystemLocale(false);
    source.setBasenames(baseNames);
    source.setUseCodeAsDefaultMessage(true);
}