Im using thymeleaf and spring, my messages.properties files need to have the same name as the template in order for them to work. I have tried to create a custom path using webConfigurer.Java but it's not working.
WebConfigurer.java source:
...
...
@EnableWebMvc
@EnableTransactionManagement
@Configuration
@ComponentScan({"en.irp.project.*"})
@PropertySource("classpath:/application.properties")
@Import({SecurityConfigurer.class})
public class WebConfigurer extends WebMvcConfigurerAdapter {
...
...
...
@Bean(name="messageSource")
public ReloadableResourceBundleMessageSource messageSource() {
ReloadableResourceBundleMessageSource resource = new ReloadableResourceBundleMessageSource();
resource.setBasename("WEB-INF/languages/messages");
resource.setDefaultEncoding("UTF-8");
return resource;
}
@Bean
public LocaleChangeInterceptor localeChangeInterceptor() {
LocaleChangeInterceptor localeChangeInterceptor = new LocaleChangeInterceptor();
localeChangeInterceptor.setParamName("language");
return localeChangeInterceptor;
}
@Bean(name = "localeResolver")
public SessionLocaleResolver localeResolver() {
SessionLocaleResolver localeResolver = new SessionLocaleResolver();
localeResolver.setDefaultLocale(new Locale("en"));
return localeResolver;
}
...
...
}
Just for future reference.
If Spring Boot is used, you can also set its custom location in application.properties file:
spring.messages.basename=i18n/messages
Javadoc:
Comma-separated list of basenames, each following the ResourceBundle convention. Essentially a fully-qualified classpath location. If it doesn't contain a package qualifier (such as "org.mypackage"), it will be resolved from the classpath root.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With