4

Since Grails 3.2.8 (and above) the resource bundle within my application does not work as expected. German umlauts (or general UTF-8 chars that are not part from ASCII) are display with ��. E.g. the German word über is displayed as ��ber.

First I suspected the processResources Gradle tasks that performs native2ascii. But my UTF-8 resource bundle files are properly copied to build/resources/main/*.properties and converted to US-ASCII.

The source file is clearly encoding using UTF-8.

file -I grails-app/i18n/messages_de.properties grails-app/i18n/messages_de.properties: text/plain; charset=utf-8

after running ./gradlew clean processResources all the resource bundle files are successfully processed by native2ascii and encoded using US-ASCII.

file -I build/resources/main/messages_de.properties
build/resources/main/messages_de.properties: text/plain; charset=us-ascii

All non ASCII chars are escaped.

event.free.space={0,number} von {1,number} verf\u00fcgbar

While debugging my application running as a standalone WAR using

java -jar -server -Dserver.address=127.0.0.1 -Dserver.port=50000 \
    -Dgrails.env=prodMySQL -Djava.security.egd=file:/dev/./urandom \
    -Xmx768M -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 \ 
    build/libs/my.war

I noticed that the org.grails.spring.context.support.PluginAwareResourceBundleMessageSource loads my messages_de.properties file using UTF-8 encoding since it logs the following message.

s.PluginAwareResourceBundleMessageSource : Loading properties [messages_de.properties] with encoding 'UTF-8'

After loading the properties file into to the a java.util.Properties class, I see all non ASCII characters as e.g. �.

Any clue whats going wrong here?

saw303
  • 8,051
  • 7
  • 50
  • 90
  • 2
    I have the same problem, opened an issue with grails-core on Github: https://github.com/grails/grails-core/issues/10832 – Alin Pandichi Oct 13 '17 at 11:52
  • I noticed that this issue only applies when I build my war using `gradlew clean build` while having my Grails project open in IntelliJ. If I close IntelliJ before building with Gradle everything works as expected. Strange behaviour.... – saw303 Oct 25 '17 at 15:55

1 Answers1

0

I had a similar issue and for me the solution was in this answer: https://stackoverflow.com/a/34268213/6899501

in resources.groovy set the defaultEncoding to 'UTF-8' for the messageSource bean.

saw303
  • 8,051
  • 7
  • 50
  • 90
JW-Munich
  • 791
  • 1
  • 7
  • 16