jeudi 9 avril 2015

How to display Spring messages in Thymeleaf?

I created a Spring Boot web application that uses Thymeleaf as the template engine. I configured the MessageSource to look for messages in a subfolder:



@Bean
public MessageSource messageSource() {
final ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();

messageSource.setBasename("i18n/messages");
messageSource.setFallbackToSystemLocale(false);
messageSource.setCacheSeconds(0);

return messageSource;
}


In this folder I created the file messages_de.properties with the content ticket.type.BUG=Fehler. In my template I try to display the text like this:



<p th:text="#{ticket.type.BUG}">BUG</p>


But when the page is rendered, I get the following:



<p>??ticket.type.BUG_de_DE??</p>


What am I missing? Do I have to configure any additional beans?


Aucun commentaire:

Enregistrer un commentaire