Example usage for org.springframework.context.support ReloadableResourceBundleMessageSource setFallbackToSystemLocale

List of usage examples for org.springframework.context.support ReloadableResourceBundleMessageSource setFallbackToSystemLocale

Introduction

In this page you can find the example usage for org.springframework.context.support ReloadableResourceBundleMessageSource setFallbackToSystemLocale.

Prototype

public void setFallbackToSystemLocale(boolean fallbackToSystemLocale) 

Source Link

Document

Set whether to fall back to the system Locale if no files for a specific Locale have been found.

Usage

From source file:net.sf.yal10n.analyzer.ExploratoryEncodingTest.java

/**
 * Test to load a resource bundle via Spring's message source when the file is
 * encoded with a BOM./*from  ww  w.j  a  va2  s  .  c om*/
 * @throws Exception any error
 */
@Test
public void testSpringMessageSourceBOMDefault() throws Exception {
    ReloadableResourceBundleMessageSource source = new ReloadableResourceBundleMessageSource();
    source.setBasename("UTF8BOM");
    source.setDefaultEncoding("UTF-8");
    source.setFallbackToSystemLocale(false);

    // Assert.assertEquals("first key", source.getMessage("testkey1", null, Locale.ROOT));
    // note: utf-8 bom read as first character
    Assert.assertEquals("first key", source.getMessage("\ufefftestkey1", null, Locale.ROOT));
    Assert.assertEquals("second key", source.getMessage("testkey2", null, Locale.ROOT));
    Assert.assertEquals("This file is encoded as UTF-8 with BOM .",
            source.getMessage("description", null, Locale.ROOT));
}

From source file:net.sf.yal10n.analyzer.ExploratoryEncodingTest.java

/**
 * Test to load a resource bundle via Spring's message source when the file
 * is encoded with a BOM and the correct encoding is used.
 * @throws Exception any error//from w  w w  . j  a  va 2  s  . c o m
 */
@Test
public void testSpringMessageSourceBOM() throws Exception {
    ReloadableResourceBundleMessageSource source = new ReloadableResourceBundleMessageSource();
    source.setBasename("UTF8BOM");
    source.setDefaultEncoding("UTF-8-BOM");
    source.setFallbackToSystemLocale(false);

    Assert.assertEquals("first key", source.getMessage("testkey1", null, Locale.ROOT));
    Assert.assertEquals("second key", source.getMessage("testkey2", null, Locale.ROOT));
    Assert.assertEquals("This file is encoded as UTF-8 with BOM .",
            source.getMessage("description", null, Locale.ROOT));
}

From source file:net.sf.yal10n.analyzer.ExploratoryEncodingTest.java

/**
 * Test to load a resource bundle via Spring's message source when the file
 * is encoded with a BOM and starts with a comment. 
 * @throws Exception any error//  w  w  w.ja v a 2  s.c  o m
 */
@Test
public void testSpringMessageSourceBOMandComment() throws Exception {
    ReloadableResourceBundleMessageSource source = new ReloadableResourceBundleMessageSource();
    source.setBasename("UTF8BOMwithComment");
    source.setDefaultEncoding("UTF-8");
    source.setFallbackToSystemLocale(false);

    Assert.assertEquals("", source.getMessage("\ufeff#abc", null, Locale.ROOT));
    Assert.assertEquals("first key", source.getMessage("testkey1", null, Locale.ROOT));
    Assert.assertEquals("second key", source.getMessage("testkey2", null, Locale.ROOT));
    Assert.assertEquals("This file is encoded as UTF-8 with BOM .",
            source.getMessage("description", null, Locale.ROOT));
}

From source file:net.sf.yal10n.analyzer.ExploratoryEncodingTest.java

/**
 * Test to load a resource bundle via Spring's message source when the file is
 * encoded with a BOM and starts with a blank line.
 * @throws Exception any error/*from w w  w . j  a v  a2s.  c om*/
 */
@Test
public void testSpringMessageSourceBOMandBlankLine() throws Exception {
    ReloadableResourceBundleMessageSource source = new ReloadableResourceBundleMessageSource();
    source.setBasename("UTF8BOMwithBlankLine");
    source.setDefaultEncoding("UTF-8");
    source.setFallbackToSystemLocale(false);

    Assert.assertEquals("first key", source.getMessage("testkey1", null, Locale.ROOT));
    Assert.assertEquals("second key", source.getMessage("testkey2", null, Locale.ROOT));
    Assert.assertEquals("This file is encoded as UTF-8 with BOM .",
            source.getMessage("description", null, Locale.ROOT));
}

From source file:br.com.joaops.awc.configuration.WebConfig.java

private MessageSource messageSource() {
    ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
    messageSource.setDefaultEncoding("UTF-8");
    messageSource.setBasenames("classpath:/org/springframework/security/messages",
            "classpath:/org/hibernate/validator/ValidationMessages");
    messageSource.setCacheSeconds(0);// ww w  .j  a va 2s.  c  om
    messageSource.setFallbackToSystemLocale(Boolean.TRUE);
    return messageSource;
}

From source file:net.sf.sze.config.WebMvcConfig.java

/**
 * Initiates the message resolver.//from   ww  w.  jav a 2  s.  c om
 *
 * @return a message source.
 */
@Bean(name = "messageSource")
public MessageSource configureMessageSource() {
    ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
    messageSource.setBasenames(MESSAGE_SOURCE, APP_MESSAGE_SOURCE, HELP_MESSAGE_SOURCE, MESSAGE_SOURCE_OVAL);
    messageSource.setCacheSeconds(MESSAGE_CACHE);
    messageSource.setFallbackToSystemLocale(false);
    // Make sure Apostrophs must always be doubled..
    messageSource.setAlwaysUseMessageFormat(true);
    // This persister doubles Apostoph
    messageSource.setPropertiesPersister(
            new RecursivePropertiesPersister(new ApostropheEscapingPropertiesPersister()));

    final Class<?>[] classes = URL.class.getDeclaredClasses();
    final UrlDefinitionsToMessages urlDefinitions = new UrlDefinitionsToMessages(classes);
    urlDefinitions.addParamGroupAsMessages();
    urlDefinitions.addParamsAsMessages();
    urlDefinitions.addUrlsAsMessagesWithNamedParameters();
    Properties staticMessages = urlDefinitions.getMessages();
    final EntityPropertiesToMessages epm = new EntityPropertiesToMessages("net.sf.sze.model");
    staticMessages.putAll(epm.getProperties());
    final String version = buildNr.replace("SNAPSHOT", Long.toString(System.currentTimeMillis()));
    staticMessages.put("app.version", version);
    messageSource.setCommonMessages(staticMessages);
    return messageSource;
}

From source file:cz.jirutka.spring.exhandler.RestHandlerExceptionResolverBuilder.java

private MessageSource createDefaultMessageSource() {

    ReloadableResourceBundleMessageSource messages = new ReloadableResourceBundleMessageSource();
    messages.setBasename(DEFAULT_MESSAGES_BASENAME);
    messages.setDefaultEncoding("UTF-8");
    messages.setFallbackToSystemLocale(false);

    return messages;
}

From source file:net.chrissearle.flickrvote.service.TestMessageSourceChallengeMessageService.java

@Before
public void setup() throws Exception {
    ConstrettoConfiguration conf = new ConstrettoBuilder().addCurrentTag("development").createPropertiesStore()
            .addResource(new DefaultResourceLoader().getResource("classpath:flickrvote.properties")).done()
            .createPropertiesStore()//from   ww  w  .j  a  v a 2s.co  m
            .addResource(new DefaultResourceLoader().getResource("file:/etc/flickrvote/flickrvote.properties"))
            .done().getConfiguration();

    ShortUrlService shortUrlService = new BitlyShortUrlService();
    ((BitlyShortUrlService) shortUrlService).configure(conf.evaluateToString("bitly.login"),
            conf.evaluateToString("bitly.key"));

    MessageSourceChallengeMessageService service = new MessageSourceChallengeMessageService(shortUrlService);

    ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
    messageSource.setBasename("classpath:messages");
    messageSource.setFallbackToSystemLocale(true);

    service.setMessageSource(messageSource);
    service.afterPropertiesSet();

    challengeMessageService = service;

    DateTime startDate = new DateTime(2009, DateTimeConstants.JANUARY, 1, 18, 0, 0, 0);

    DateTime voteDate = startDate.plusDays(5);

    DateTime endDate = startDate.plusDays(7).plusHours(3);

    TestChallengeSummary testChallenge = new TestChallengeSummary();
    testChallenge.setTag("TestTag");
    testChallenge.setTitle("Test Name");
    testChallenge.setStartDate(startDate.toDate());
    testChallenge.setEndDate(endDate.toDate());
    testChallenge.setVoteDate(voteDate.toDate());

    challenge = testChallenge;

    resultsUrl = challengeMessageService.getResultsUrl(challenge);
}

From source file:com.acc.storefront.web.theme.StorefrontResourceBundleSource.java

protected AbstractMessageSource createMessageSource(final String basename) {
    final ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
    messageSource.setBasename(basename);
    messageSource.setCacheSeconds(getCacheSeconds());
    messageSource.setResourceLoader(getResourceLoader());
    messageSource.setFallbackToSystemLocale(fallbackToSystemLocale);
    messageSource.setDefaultEncoding(getDefaultEncoding());
    return messageSource;
}

From source file:br.com.joaops.smt.configuration.WebConfig.java

private MessageSource messageSource() {
    ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
    messageSource.setDefaultEncoding("UTF-8");
    messageSource.setBasenames("classpath:/org/springframework/security/messages",
            "classpath:/org/hibernate/validator/ValidationMessages",
            "classpath:/br/com/joaops/smt/i18n/messages");
    messageSource.setCacheSeconds(0); //Escolher um valor do cache na hora da implantao. Para testes deixar como '0' zero
    messageSource.setFallbackToSystemLocale(Boolean.TRUE);
    return messageSource;
}