2

In springboot i have messages_fr.properties. I have a value that is publicités, images clés but it displays as publicit�s, images cl�s.

I have tried setting UTF-8, not working. Below is my code.

@Bean
    public MessageSource messageSource() {
        ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
        messageSource.setBasenames("classpath:messages");
        messageSource.setDefaultEncoding("UTF-8");
        return messageSource;
    }

This is how i fetch the key :-

messageSource.getMessage(myKey, null, Locale.French)

Please advise if i have to add anything.

sTg
  • 4,313
  • 16
  • 68
  • 115
  • What Java version are you running ? Java 9 and higher, this should just work. Java 8 requires escaping special characters: https://stackoverflow.com/a/4660195/1076463 – Robin Nov 02 '21 at 12:05
  • 1
    I am using Java 11 – sTg Nov 02 '21 at 12:06
  • 1
    Is the file itself encoded in UTF-8? I would use external editor to verify this. E.g. on Windows you can use Notepad++ -> encode in UTF-8. On Linux Sublime should do the trick. – Boris Strandjev Nov 02 '21 at 12:09
  • @BorisStrandjev - Done that.. I had pasted the contents in Notepad++ to check in Encoding menu...It showed UTF-8 – sTg Nov 02 '21 at 12:11
  • 1
    These artifacts usually happen between UTF-8 with BOM and without BOM. Rather than pasting the contents in Notepad ++ use Notepad++ File-> open and navigate to your file. Then you can convert to UTF-8 with BOM and UTF-8 without BOM. Do both conversions and see if any of it will change what you see in Notepad++ and then what you see after running your code. – Boris Strandjev Nov 02 '21 at 13:32

0 Answers0