Search in sources :

Example 6 with ReloadableResourceBundleMessageSource

use of org.springframework.context.support.ReloadableResourceBundleMessageSource in project survey by markoniemi.

the class WebMvcConfig method getMessageSource.

@Bean(name = "messageSource")
public ReloadableResourceBundleMessageSource getMessageSource() {
    ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
    messageSource.setBasenames("classpath:MessageResources", "classpath:server");
    messageSource.setFallbackToSystemLocale(false);
    messageSource.setUseCodeAsDefaultMessage(true);
    messageSource.setDefaultEncoding("UTF-8");
    return messageSource;
}
Also used : ReloadableResourceBundleMessageSource(org.springframework.context.support.ReloadableResourceBundleMessageSource) ServletRegistrationBean(org.springframework.boot.web.servlet.ServletRegistrationBean) Bean(org.springframework.context.annotation.Bean)

Example 7 with ReloadableResourceBundleMessageSource

use of org.springframework.context.support.ReloadableResourceBundleMessageSource in project gocd by gocd.

the class LocalizerTest method shouldReturnTheFormattedLocalizedMessage.

@Test
public void shouldReturnTheFormattedLocalizedMessage() {
    CurrentLocale locale = new CurrentLocale();
    ReloadableResourceBundleMessageSource source = new ReloadableResourceBundleMessageSource();
    source.setBasename("test_message");
    MessageSourceAccessor accessor = new MessageSourceAccessor(source);
    Localizer localizer = new Localizer(accessor, locale);
    assertThat(localizer.localize("hello_world"), is("Hello World"));
    locale.setLocaleString(Localizer.LOCALE_ENGLISH_US);
    assertThat(localizer.localize("MY_HOME", "San Francisco"), is("My home is San Francisco"));
    locale.setLocaleString(Localizer.LOCALE_KANNADA);
    assertThat(localizer.localize("MY_HOME", "ಬೆಂಗಳೂರು"), is("ನಮ್ಮ ಊರು ಬೆಂಗಳೂರು"));
    locale.setLocaleString(Localizer.LOCALE_KANNADA);
    assertThat(localizer.localize("MY_BIRTHDAY", new DateTime(1984, 12, 23, 14, 0, 0, 0, DateTimeZone.UTC).toDate()), is("ನನ್ನ ಹುಟ್ಟು ಹಬ್ಬ 12/23/84"));
    locale.setLocaleString(Localizer.LOCALE_ENGLISH_US);
    assertThat(localizer.localize("MY_BIRTHDAY", new DateTime(1984, 12, 23, 14, 0, 0, 0, DateTimeZone.UTC).toDate()), is("My birthday is 12/23/84"));
}
Also used : MessageSourceAccessor(org.springframework.context.support.MessageSourceAccessor) ReloadableResourceBundleMessageSource(org.springframework.context.support.ReloadableResourceBundleMessageSource) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 8 with ReloadableResourceBundleMessageSource

use of org.springframework.context.support.ReloadableResourceBundleMessageSource in project gocd by gocd.

the class LocalizerTest method shouldReturnTheLocalizedMessageForTheCurrentLocale.

@Test
public void shouldReturnTheLocalizedMessageForTheCurrentLocale() {
    CurrentLocale locale = new CurrentLocale();
    ReloadableResourceBundleMessageSource source = new ReloadableResourceBundleMessageSource();
    source.setBasename("test_message");
    MessageSourceAccessor accessor = new MessageSourceAccessor(source);
    Localizer localizer = new Localizer(accessor, locale);
    assertThat(localizer.localize("hello_world"), is("Hello World"));
    locale.setLocaleString(Localizer.LOCALE_KANNADA);
    assertThat(localizer.localize("hello_world"), is("ನಮಸ್ಕಾರ"));
}
Also used : MessageSourceAccessor(org.springframework.context.support.MessageSourceAccessor) ReloadableResourceBundleMessageSource(org.springframework.context.support.ReloadableResourceBundleMessageSource) Test(org.junit.Test)

Example 9 with ReloadableResourceBundleMessageSource

use of org.springframework.context.support.ReloadableResourceBundleMessageSource in project ArachneCentralAPI by OHDSI.

the class WebConfig method messageSource.

@Bean
public MessageSource messageSource() {
    ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
    messageSource.setBasename("classpath:messages");
    // refresh cache once per hour
    messageSource.setCacheSeconds(3600);
    return messageSource;
}
Also used : ReloadableResourceBundleMessageSource(org.springframework.context.support.ReloadableResourceBundleMessageSource) Bean(org.springframework.context.annotation.Bean) LocalValidatorFactoryBean(org.springframework.validation.beanvalidation.LocalValidatorFactoryBean)

Example 10 with ReloadableResourceBundleMessageSource

use of org.springframework.context.support.ReloadableResourceBundleMessageSource in project paascloud-master by paascloud.

the class PaasCloudUacApplication method messageSource.

@Bean
public ReloadableResourceBundleMessageSource messageSource() {
    ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
    messageSource.setBasename("classpath:org/springframework/security/messages_zh_CN");
    return messageSource;
}
Also used : ReloadableResourceBundleMessageSource(org.springframework.context.support.ReloadableResourceBundleMessageSource) Bean(org.springframework.context.annotation.Bean)

Aggregations

ReloadableResourceBundleMessageSource (org.springframework.context.support.ReloadableResourceBundleMessageSource)15 Bean (org.springframework.context.annotation.Bean)10 Test (org.junit.Test)3 MessageSourceAccessor (org.springframework.context.support.MessageSourceAccessor)3 LocalValidatorFactoryBean (org.springframework.validation.beanvalidation.LocalValidatorFactoryBean)3 Properties (java.util.Properties)2 InputStream (java.io.InputStream)1 DateTime (org.joda.time.DateTime)1 Duration (org.joda.time.Duration)1 Before (org.junit.Before)1 ServletRegistrationBean (org.springframework.boot.web.servlet.ServletRegistrationBean)1