How to include message.properties with thymeleaf

16,745

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.

Share:
16,745

Related videos on Youtube

osagie
Author by

osagie

Updated on June 30, 2022

Comments

  • osagie
    osagie almost 2 years

    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?

    • Pedro Affonso
      Pedro Affonso about 9 years
      Looks like you need to configure your message source (set the directory where spring will look for messages.properties)
    • M. Deinum
      M. Deinum about 9 years
      Rename message.properties to messages.properties.