1

I have 4 locales in my resources folder which I'm loading exactly as shown in this example: https://github.com/jtwig/jtwig-examples/blob/master/gradle-jtwig-translate-extension-properties/src/main/java/org/jtwig/example/translate/SimpleAppWithTranslate.java

However the properties are not loaded with the correct encoding.

E.g. the German Grüsse from the property file becomes Grüsse once loaded via Jtwig's PropertiesLocalizedMessageResourceLoader. It happens in this part of the example code:

propertiesMessageSource()
  .withLookupClasspath("translations")
  .build()

Is there an easy way to load the property files in UTF-8 using something like the code from the link above?

P.S. I'm using Java 11

emazzotta
  • 1,879
  • 3
  • 20
  • 31
  • 1
    You can't, because properties files are required to be encoded in **ISO 8859-1** as specified in the [javadoc of Properties.read(InputStream)](https://docs.oracle.com/javase/8/docs/api/java/util/Properties.html#load-java.io.InputStream-) – Thomas Fritsch Nov 21 '18 at 13:30
  • 1
    You need to use escaping in properties file, e.g. `Gr\u00FCe` instead of `Grüsse`. – Thomas Fritsch Nov 21 '18 at 13:39
  • @ThomasFritsch thanks, that's what I'm currently doing as a work-around, I was hoping I could avoid that. – emazzotta Nov 21 '18 at 13:40
  • Linking the ISO 8859-1 character list here for reference: http://www.fileformat.info/info/charset/ISO-8859-1/list.htm – emazzotta May 16 '19 at 14:51
  • This tool can convert native characters to ascii: https://docs.oracle.com/javase/7/docs/technotes/tools/solaris/native2ascii.html – emazzotta Jul 29 '19 at 11:47

0 Answers0