Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include message.properties with thymeleaf

I am using spring boot with thymeleaf. This is my project structure: enter image description here

And this is my App start class:

    @EnableAutoConfiguration
@Configuration
@ComponentScan
public class App {
    public static void main(String[] args) {
        SpringApplication.run(App.class);
    }
}

I have this on my home.leaf.html: <p th:text = "#{username}"></p>

But when I run this application this is what I get: ??username_en_US??

I have tried various things on how to resolve this configuration issue. Please, can anyone help?

like image 772
osagie Avatar asked Dec 24 '22 19:12

osagie


1 Answers

Refer the official documentation for spring boot

http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#howto-convert-an-existing-application-to-spring-boot

It says

Static resources can be moved to /public (or /static or /resources or /META-INF/resources) in the classpath root. Same for messages.properties (Spring Boot detects this automatically in the root of the classpath).

So you should create ur internationalization file as messages.properties and place in the root classpath.

Or you can also edit the default location to a more proper location by adding this entry in the application.properties file

#messages
spring.messages.basename=locale/messages

so you can store your files in the locale folder inside resources folder, with the name messages.properties or in any specific language.

like image 70
Faraj Farook Avatar answered Jan 09 '23 04:01

Faraj Farook