I am trying to internationalise my application, which is supposed to send emails in different languages. I created messages.properties files for all the languages and default (messages_en.properties, messages_de.properties, messages.properties…). I put them under “/resources” along with the templates using the keys inside of these .properties files.
I also created a configuration class for the MessageSource and injected it into my service class sending the emails:
@Configuration
public class MessageSourceConfiguration {
@Bean
public MessageSource messageSource() {
ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
messageSource.setBasename("classpath:messages");
messageSource.setDefaultEncoding("UTF-8");
return messageSource;
}
}
The language is taken from the accept-language header (when null or language not supported it falls back to English) and put into the Thymeleaf context with .setLocale(). My application is hosted on Kubernetes.
When testing it, the messages sent are always with the values taken from the messages_en.properties files. Am I missing something or why is it not taking the keys and values from the other .properties files and the default language instead? Thank you in advance!