2

由于 Grails 3.2.8(及更高版本),我的应用程序中的资源包无法按预期工作。德语变音符号(或不属于 ASCII 的一般 UTF-8 字符)以 �� 显示。例如,德语单词über显示为��ber

首先,我怀疑processResources执行的 Gradle 任务native2ascii。但是我的 UTF-8 资源包文件已正确复制build/resources/main/*.properties并转换为US-ASCII.

源文件显然是使用 UTF-8 编码的。

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

运行./gradlew clean processResources所有资源包文件后,都native2ascii使用US-ASCII.

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

所有非 ASCII 字符都被转义。

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

在调试我的应用程序作为独立 WAR 运行时,使用

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

我注意到org.grails.spring.context.support.PluginAwareResourceBundleMessageSource加载我的messages_de.properties文件时使用 UTF-8 编码,因为它记录了以下消息。

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

将属性文件加载到 ajava.util.Properties类后,我看到所有非 ASCII 字符为例如 �。

任何线索这里出了什么问题?

4

1 回答 1

0

我有一个类似的问题,对我来说,解决方案在这个答案中: https ://stackoverflow.com/a/34268213/6899501

在为beanresources.groovy设置defaultEncodingto中。'UTF-8'messageSource

于 2018-07-26T09:26:09.530 回答