List of usage examples for org.springframework.context.support ReloadableResourceBundleMessageSource ReloadableResourceBundleMessageSource
ReloadableResourceBundleMessageSource
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 .ja v a 2 s . co m*/ * @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:com.orange.mmp.i18n.helpers.DefaultInternationalizationManager.java
/** * Adds a MessageSource from a module//w w w. jav a2s .co m * * @param module The module owning the MessageSource * @throws MMPException */ private void addModuleMessageSource(Module module) throws MMPException { try { MMPConfig moduleConfiguration = ModuleContainerFactory.getInstance().getModuleContainer() .getModuleConfiguration(module); if (moduleConfiguration != null && moduleConfiguration.getMessagesource() != null) { for (MMPConfig.Messagesource messageSourceConfig : moduleConfiguration.getMessagesource()) { if (messageSourceConfig.getOtherAttributes().get(I18N_CONFIG_MS_LOCATION) != null && messageSourceConfig.getOtherAttributes().get(I18N_CONFIG_MS_BASENAME) != null) { String messageSourceName = messageSourceConfig.getName(); String location = messageSourceConfig.getOtherAttributes().get(I18N_CONFIG_MS_LOCATION); String basename = messageSourceConfig.getOtherAttributes().get(I18N_CONFIG_MS_BASENAME); List<URL> locations = ModuleContainerFactory.getInstance().getModuleContainer() .findModuleResource(module, location, basename + "*", false); String messageSourceFolderBase = this.messageBasePath + "/" + messageSourceName; FileUtils.forceMkdir(new File(messageSourceFolderBase)); //Copy I18N resources on shared repository (Only master server) if (ApplicationController.getInstance().isMaster()) { String fileName = null; for (URL messageUrl : locations) { InputStream in = null; OutputStream out = null; try { in = messageUrl.openStream(); String filePath = messageUrl.getPath(); fileName = filePath.substring(filePath.lastIndexOf("/") + 1); out = new FileOutputStream(new File(messageSourceFolderBase, fileName)); IOUtils.copy(in, out); } finally { if (in != null) { in.close(); } if (out != null) { out.close(); } } } } ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource(); messageSource.setDefaultEncoding("UTF-8"); messageSource.setBasename("file://" + messageSourceFolderBase + "/" + basename); this.messageSourceMap.put(messageSourceName, messageSource); //Keep file path for the translation i18nFilesPathByMessageSource.put(messageSourceName, messageSourceFolderBase + "/" + basename); } } } } catch (IOException ioe) { throw new MMPI18NException("Failed to load " + module.getName() + " I18N configuration"); } }
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/* ww w . j a v a 2 s . 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: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/*from w w w .j a va 2 s . c om*/ */ @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 the correct encoding is used. * @throws Exception any error//from w w w. j a v a2s . 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: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: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:org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration.java
/** * The {@link MessageSourceAccessor} to provide messages for {@link ResourceDescription}s being rendered. * // www .j av a 2 s . c o m * @return */ @Bean public MessageSourceAccessor resourceDescriptionMessageSourceAccessor() { try { PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean(); propertiesFactoryBean.setLocation(new ClassPathResource("rest-default-messages.properties")); propertiesFactoryBean.afterPropertiesSet(); ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource(); messageSource.setBasename("classpath:rest-messages"); messageSource.setCommonMessages(propertiesFactoryBean.getObject()); messageSource.setDefaultEncoding("UTF-8"); return new MessageSourceAccessor(messageSource); } catch (Exception o_O) { throw new BeanCreationException("resourceDescriptionMessageSourceAccessor", "", o_O); } }
From source file:org.benetech.secureapp.generator.SecureAppGeneratorApplication.java
private static MessageSource getMessageSource() { ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource(); messageSource.setBasenames("classpath:/messages"); messageSource.setUseCodeAsDefaultMessage(true); messageSource.setDefaultEncoding("UTF-8"); messageSource.setCacheSeconds(0);//w w w. ja va2 s .c o m return messageSource; }
From source file:org.egov.infra.config.properties.MessageSourceConfiguration.java
@Bean public ReloadableResourceBundleMessageSource parentMessageSource() { final ReloadableResourceBundleMessageSource resource = new ReloadableResourceBundleMessageSource(); resource.setBasenames(processResourceWithPattern(commonMessageFiles)); resource.setDefaultEncoding(Charset.defaultCharset().name()); if (devMode) { resource.setCacheSeconds(0);/*from ww w.j ava 2 s. c o m*/ resource.setUseCodeAsDefaultMessage(true); } return resource; }