How to display messages in Thymeleaf and Spring Boot?

stevecross

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?

P.S.:

On the 'server side' I am able to obtain the message using MessageSource#getMessage("ticket.type.BUG", null, Locale.GERMANY).

stevecross

Because I am using Spring Boot, the MessageSource is configured with a MessageSourceAutoConfiguration. These settings can be easily changed in the application.properties file. In my case I had to add the following to this file:

spring.messages.basename=i18n/messages

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Thymeleaf + Spring (not Boot) - how to show messages from messageSource

Spring boot thymeleaf display of productName

Display images with Thymeleaf - Spring Boot

How to display the contents of <td> in two different lines in Thymeleaf and Spring Boot?

How can I display the current logged in User with Spring Boot Thymeleaf?

Spring boot thymeleaf cannot resolve arabic messages

Spring boot + Thymeleaf custom error messages

Unable to Display Spring Boot Model Data in Thymeleaf

Spring-boot Thymeleaf: How do I display an entity name from the database and make that name a hyperlink?

how to override default thymeleaf resolver in spring boot

How to locate Thymeleaf template from spring boot

Spring Boot Thymeleaf: How to include html file

How to use Thymeleaf for JavaScript in Spring Boot?

How to load an image in spring boot with thymeleaf?

how to validate email spring boot thymeleaf

Display a String in a view returned by a Spring Boot Thymeleaf controller

Thymeleaf + Spring boot - use getter method to display image

Can't display an image in the Thymeleaf/Spring Boot App

Display files (pdf, doc, ppt) from MySQL to Thymeleaf with Spring Boot

Spring Boot Thymeleaf Dropdown List option doesn't display values

Spring + thymeleaf html email templates, how to add html tags in messages?

How to show localization messages with parameters in Spring 3 / Thymeleaf

How to get local to spring boot to localize messages?

Spring Boot - Thymeleaf template

spring boot and thymeleaf

Pagination with Spring Boot and Thymeleaf

Spring Boot, Thymeleaf and @Controller

Spring Boot, Thymeleaf and CSS

Issues with Spring Boot and Thymeleaf