@Override public MessageSource getMessageService(String messageFilename) { if (messageFilename != null) { MessageSource ms = messageServices.get(messageFilename); if (ms == null) { ResourceBundleMessageSource rbms = (ResourceBundleMessageSource) beanFactory .getBean(LOADED_MESSAGE_SOURCE_BEAN); rbms.setBasename(messageFilename); messageServices.put(messageFilename, rbms); ms = rbms; } return ms; } else { return null; } }
@Test public void simpleTest() throws Throwable { try { String dir = this.getClass().getResource("/").getFile(); String resource = "writer"; File dirFile = new File(dir); new PropertiesWriter().writePropertiesSet(this.messages(), new Locale("de"), resource, dirFile, "ISO-8859-1"); ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource(); messageSource.setBasename(resource); Assert.assertEquals(FR_TEST, messageSource.getMessage("test.key", null, new Locale("fr"))); Assert.assertEquals(DE_TEST, messageSource.getMessage("test.key", null, new Locale("de"))); } finally { } }
@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); }
/** * Checks JSTL's "javax.servlet.jsp.jstl.fmt.localizationContext" * context-param and creates a corresponding child message source, * with the provided Spring-defined MessageSource as parent. * @param servletContext the ServletContext we're running in * (to check JSTL-related context-params in {@code web.xml}) * @param messageSource the MessageSource to expose, typically * the ApplicationContext of the current DispatcherServlet * @return the MessageSource to expose to JSTL; first checking the * JSTL-defined bundle, then the Spring-defined MessageSource * @see org.springframework.context.ApplicationContext */ public static MessageSource getJstlAwareMessageSource( ServletContext servletContext, MessageSource messageSource) { if (servletContext != null) { String jstlInitParam = servletContext.getInitParameter(Config.FMT_LOCALIZATION_CONTEXT); if (jstlInitParam != null) { // Create a ResourceBundleMessageSource for the specified resource bundle // basename in the JSTL context-param in web.xml, wiring it with the given // Spring-defined MessageSource as parent. ResourceBundleMessageSource jstlBundleWrapper = new ResourceBundleMessageSource(); jstlBundleWrapper.setBasename(jstlInitParam); jstlBundleWrapper.setParentMessageSource(messageSource); return jstlBundleWrapper; } } return messageSource; }
public void init() { URL url = buildMidpointHomeLocalizationFolderUrl(); ClassLoader classLoader = new URLClassLoader(new URL[]{url}, null); sources.add(buildSource("Midpoint", classLoader)); sources.add(buildSource(SchemaConstants.BUNDLE_NAME, classLoader)); sources.add(buildSource("localization/Midpoint", null)); sources.add(buildSource(SchemaConstants.SCHEMA_LOCALIZATION_PROPERTIES_RESOURCE_BASE_PATH, null)); // model security messages as fallback ResourceBundleMessageSource modelSecurity = new ResourceBundleMessageSource(); modelSecurity.setBasename("com.evolveum.midpoint.security"); sources.add(modelSecurity); // spring security messages as a fallback ResourceBundleMessageSource springSecurity = new ResourceBundleMessageSource(); springSecurity.setBasename("org.springframework.security.messages"); sources.add(springSecurity); }
@Override public void resolve(Component component) { if( component.isPlain()) return; logger.debug("Resolving {} {} feature", component, getName()); ApplicationContext parent = resolveContext.getRootContext() ; ClassLoader realm = component.getClassLoader(); //在根据配置的情况下,根据 manifest里面的App-Message加载资源 String appMessage = getAppMessage(component); if(StringUtils.isNotBlank(appMessage)){ CombinedMessageSource combined = parent.getBean(CombinedMessageSource.class); ResourceBundleMessageSource source = new ResourceBundleMessageSource(); source.setBundleClassLoader(realm); source.setBasenames(StringUtils.split(appMessage, CONFIG_LOCATION_DELIMITERS)); combined.combine(source); } resolveContext.registerFeature(component, getName(), realm); }
@BeforeClass public void beforeClass() { AllPropertiesMessageSource molgenisLocalizationMessages = new AllPropertiesMessageSource(); molgenisLocalizationMessages.addMolgenisNamespaces("web"); ResourceBundleMessageSource hibernateValidationMessages = new ResourceBundleMessageSource(); hibernateValidationMessages.addBasenames("org.hibernate.validator.ValidationMessages"); molgenisLocalizationMessages.setParentMessageSource(hibernateValidationMessages); MessageSourceHolder.setMessageSource(molgenisLocalizationMessages); globalError = new ObjectError("entityCollectionRequestV2", new String[] { "TwoFieldsSet" }, new Object[] { 1 }, "must have two fields set"); fieldError = new FieldError("entityCollectionRequestV2", "num", -10, false, new String[] { "Min.entityCollectionRequestV2.num", "Min.num", "Min.int", "Min" }, new Object[] { new DefaultMessageSourceResolvable(new String[] { "entityCollectionRequestV2.num", "num" }, null, "num"), 0 }, "must be greater than or equal to 0"); }
@Bean public ResourceBundleMessageSource messageSource() { ResourceBundleMessageSource source = new ResourceBundleMessageSource(); source.setBasename("locale/messages"); source.setDefaultEncoding("UTF-8"); return source; }
@Override protected MessageSource createMessageSource(String basename) { ResourceBundleMessageSource messageSource = (ResourceBundleMessageSource) super.createMessageSource(basename); // Create parent theme recursively. for (Theme theme : settingsService.getAvailableThemes()) { if (basename.equals(basenamePrefix + theme.getId()) && theme.getParent() != null) { String parent = basenamePrefix + theme.getParent(); messageSource.setParentMessageSource(createMessageSource(parent)); break; } } return messageSource; }
@Bean public MessageSource mailMessageSource() { ResourceBundleMessageSource msgsource = new ResourceBundleMessageSource(); if (nixmashModeEnabled) msgsource.setBasename("mail-nixmash"); else msgsource.setBasename("mail-messages"); return msgsource; }
@Bean public MessageSource messageSource() { ResourceBundleMessageSource msgsource = new ResourceBundleMessageSource(); if (nixmashModeEnabled) msgsource.setBasename("nixmash"); else msgsource.setBasename("messages"); msgsource.setUseCodeAsDefaultMessage( Boolean.parseBoolean(environment.getRequiredProperty(USE_CODE_AS_DEFAULT_MESSAGE))); return msgsource; }
@Bean public MessageSource defaultMessageSource() { ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource(); messageSource.setBasenames("messages", "i18n/messages"); messageSource.setDefaultEncoding(Charset.forName("UTF-8").name()); messageSource.setFallbackToSystemLocale(true); messageSource.setCacheSeconds(-1); messageSource.setAlwaysUseMessageFormat(false); messageSource.setUseCodeAsDefaultMessage(true); return messageSource; }
/** * @return ResourceBundleMessageSource pour les messages de l'application */ @Bean public ResourceBundleMessageSource messageSource() { ResourceBundleMessageSource resourceBundleMessageSource = new ResourceBundleMessageSource(); resourceBundleMessageSource.setBasenames( "i18n/messages", "i18n/backoffice/backoffice-messages", "i18n/backoffice/nomenclature-messages", "i18n/candidat/candidat-messages"); resourceBundleMessageSource.setFallbackToSystemLocale(false); return resourceBundleMessageSource; }
@Bean public ResourceBundleMessageSource messageSource() { ResourceBundleMessageSource source = new ResourceBundleMessageSource(); source.setBasenames("i18n/messages"); source.setUseCodeAsDefaultMessage(true); source.setDefaultEncoding("UTF-8"); return source; }
@Bean public MessageSource messageSource() { ResourceBundleMessageSource resourceBundleMessageSource = new ResourceBundleMessageSource(); resourceBundleMessageSource.setDefaultEncoding("UTF-8"); resourceBundleMessageSource.addBasenames("templates/index"); return resourceBundleMessageSource; }
@Bean(name = "messageSource") public MessageSource getMessageSource() { ResourceBundleMessageSource resource = new ResourceBundleMessageSource(); resource.setBasename("messages"); resource.setDefaultEncoding("UTF-8"); return resource; }
/** * Create a MessageSource for the given basename, * to be used as MessageSource for the corresponding theme. * <p>Default implementation creates a ResourceBundleMessageSource. * for the given basename. A subclass could create a specifically * configured ReloadableResourceBundleMessageSource, for example. * @param basename the basename to create a MessageSource for * @return the MessageSource * @see org.springframework.context.support.ResourceBundleMessageSource * @see org.springframework.context.support.ReloadableResourceBundleMessageSource */ protected MessageSource createMessageSource(String basename) { ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource(); messageSource.setBasename(basename); if (this.defaultEncoding != null) { messageSource.setDefaultEncoding(this.defaultEncoding); } if (this.fallbackToSystemLocale != null) { messageSource.setFallbackToSystemLocale(this.fallbackToSystemLocale); } if (this.beanClassLoader != null) { messageSource.setBeanClassLoader(this.beanClassLoader); } return messageSource; }
@Before public void before() { ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource(); messageSource.setBasenames("messages"); messageSource.setDefaultEncoding("UTF8"); clientEnumController = new ClientEnumController(messageSource); clientEnumController.registerClientEnum(Gender.class); }
@Bean public MessageSource validationMessageSource() { ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource(); messageSource.setBasenames("validation"); messageSource.setDefaultEncoding("utf8"); return messageSource; }
public static Validator createValidator() { LocaleContextHolder.setLocale(Locale.ENGLISH); ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource(); messageSource.setFallbackToSystemLocale(false); messageSource.setBasenames("validation"); messageSource.setDefaultEncoding("utf8"); LocalValidatorFactoryBean localValidator = new LocalValidatorFactoryBean(); localValidator.setValidationMessageSource(messageSource); localValidator.afterPropertiesSet(); return localValidator; }
@Bean public ResourceBundleMessageSource messageSource() { ResourceBundleMessageSource bundleMessageSource = new ResourceBundleMessageSource(); bundleMessageSource.setUseCodeAsDefaultMessage(true); bundleMessageSource.setBasenames(i18nMessages.split(",")); return bundleMessageSource; }
private String validateSubmission(SubmissionJudge submit, int lid){ String errors = null; ResourceBundleMessageSource r=new ResourceBundleMessageSource(); r.setBasename("messages_en"); submit.getLanguageIdByKey(); try{ if (!utilDAO.bool("submit.enabled")) return r.getMessage("errormsg.43", null, new Locale("en")).toLowerCase(); if (!problemDAO.exists(submit.getPid()) || !problemDAO.isEnabled(submit.getPid())) return r.getMessage("errormsg.25", null, new Locale("en")).toLowerCase(); if (problemDAO.isDisable24h(submit.getPid())) return r.getMessage("errormsg.25", null, new Locale("en")).toLowerCase(); int problemSourceLimit = problemDAO.getSourceLimitByPid(submit.getPid(), lid); if (submit.getCode().length() == 0) return r.getMessage("errormsg.27", null, new Locale("en")).toLowerCase(); if (submit.getCode().length() > problemSourceLimit) return r.getMessage("errormsg.28", null, new Locale("en")).toLowerCase(); }catch(Exception e){ errors = r.getMessage("errormsg.43", null, new Locale("en")).toLowerCase(); } return errors; }
private String validateEmail(Mail mail) { String errors = null; ResourceBundleMessageSource r=new ResourceBundleMessageSource(); r.setBasename("messages_en"); try { if((mail.getTitle() == null || mail.getTitle().length() == 0) && (mail.getContent() == null || mail.getContent().length() == 0)) return r.getMessage("errormsg.39",null, new Locale("en")).toLowerCase(); if(mail.getUsernameTo().equals("") || mail.getUsernameTo() == null) return r.getMessage("errormsg.40",null, new Locale("en")).toLowerCase(); String[] to = mail.getUsernameTo().split(";"); if (to.length <= 10) { for (String to1 : to) { String string = to1.replaceAll(" ", ""); if (!userDAO.isUser(string)) { return r.getMessage("errormsg.41",null, new Locale("en")).toLowerCase(); } } } else return r.getMessage("errormsg.42",null, new Locale("en")).toLowerCase(); Mail m1 = mailDAO.getMailValues(mail.getId_from()); int max = m1.getMail_quote(); int consumed = m1.getConsumed_quote(); int msgSize = mail.getContent().getBytes().length + mail.getTitle().getBytes().length; if (consumed + msgSize > max) return "quote overflow"; return errors; } catch (Exception e) { errors = "no valid mail"; } return errors; }
@Bean @Qualifier("wte4j-showcase") public MessageFactory messageFactoryShowcase() { ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource(); messageSource.setBasename("org.wte4j.examples.showcase.shared.Messages"); return new MessageFactoryImpl(messageSource, serviceContext); }
@Bean @Qualifier("wte4j-admin") public MessageFactory messageFactory() { ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource(); messageSource.setBasename("org.wte4j.ui.shared.Messages"); return new MessageFactoryImpl(messageSource, serviceContext); }
@Bean public ResourceBundleMessageSource messageSource() { ResourceBundleMessageSource resource = new ResourceBundleMessageSource(); resource.setBasename("messages"); resource.setDefaultEncoding(StandardCharsets.UTF_8.toString()); return resource; }
/** * @see org.springframework.ui.context.ThemeSource#getTheme(java.lang.String) */ @Override public Theme getTheme(String ignoredArgument) { ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource(); messageSource.setBasename(this.themeName); return new SimpleTheme(themeName, messageSource); }
@Bean public ResourceBundleMessageSource searchOperations() { ResourceBundleMessageSource bundle = new ResourceBundleMessageSource(); bundle.setFallbackToSystemLocale(false); bundle.setBasenames("com/jongsoft/harvester/service/operations"); bundle.setBundleClassLoader(ServiceConfiguration.class.getClassLoader()); return bundle; }
@Bean public MessageSource messageSource() { ResourceBundleMessageSource result = new ResourceBundleMessageSource(); result.setBasename("messages"); result.setFallbackToSystemLocale(false); return result; }
@Before public void mailSetup() { configuration = new Configuration(Configuration.VERSION_2_3_21); configuration.setDefaultEncoding("UTF-8"); configuration.setTemplateLoader(new ClassTemplateLoader(MailComposer.class, "/mail")); //keep config same as application.yml and WebConfiguration.java messageSource = new ResourceBundleMessageSource(); messageSource.setBasename("i18n/messages"); messageSource.setDefaultEncoding("UTF-8"); messageSource.setFallbackToSystemLocale(false); }
@Bean public ResourceBundleMessageSource smsMessageSource() { final ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource(); messageSource.setFallbackToSystemLocale(false); messageSource.setBasename("templates.sms.messages"); return messageSource; }
@Bean public ResourceBundleMessageSource emailMessageSource() { final ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource(); messageSource.setFallbackToSystemLocale(false); messageSource.setBasename("templates.email.messages"); return messageSource; }
@Bean public ResourceBundleMessageSource messageSource() { ResourceBundleMessageSource resourceBundleMessageSource = new ResourceBundleMessageSource(); resourceBundleMessageSource.setBasenames("GerenciarUsuarios"); resourceBundleMessageSource.setDefaultEncoding("UTF-8"); return resourceBundleMessageSource; }
@Bean public ResourceBundleMessageSource messageSource() { ResourceBundleMessageSource source = new ResourceBundleMessageSource(); source.setBasenames("i18n/message"); source.setUseCodeAsDefaultMessage(true); return source; }
@Bean public MessageSource messageSource() { ResourceBundleMessageSource source = new ResourceBundleMessageSource(); source.setBasename("i18n/messages"); source.setUseCodeAsDefaultMessage(true); return source; }
private ResourceBundleMessageSource buildSource(String basename, ClassLoader classLoader) { ResourceBundleMessageSource source = new ResourceBundleMessageSource(); source.setDefaultEncoding(StandardCharsets.UTF_8.name()); source.setFallbackToSystemLocale(false); source.setBasename(basename); if (classLoader == null) { classLoader = LocalizationServiceImpl.class.getClassLoader(); } source.setBundleClassLoader(classLoader); return source; }