spring-bootinternationalizationthymeleafproperties-file

In Spring boot, I'm trying to create another .property file that functions like messages.property, Is that possible?


So I'm trying to create another .property file (called labels.properties) that i can use in Thymeleaf like this:

<div th:text=#{property.from.labels}></div>

Right now I just add labels.properties in the root of resource folder, for now its not working. The purpose of this is I want to separate the property file that handles the error messages from texts for labels & buttons.

  1. Is that possible?
  2. if yes, how to do it?
  3. if yes again, can I do internationalization like adding labels_ja.properties (Japanese)?

Solution

  • You can customize the naming (and location) of the message bundles by configuring the spring.messages.basename property. For example:

    spring.messages.basename=labels
    

    By doing so, Spring will look for messages within classpath:labels.properties and classpath:labels_{locale}.properties, such as classpath:labels_ja.properties.

    If you want to use this in addition to the regular messages.properties file, you can use a comma separated value:

    spring.messages.basename=messages,labels
    

    The first one within that comma separated list will take priority over the other ones. If you have a property.from.labels in both messages.properties and labels.properties, the one within messages.properties would be chosen in this example.

    This can also be found within the Spring Boot Reference Documentation at the Internationalization section.