【问题标题】:Grails 3.2 Resource Bundle does not display text with correct encodingGrails 3.2 资源包不显示具有正确编码的文本
【发布时间】:2017-06-05 09:32:41
【问题描述】:

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

首先我怀疑执行native2asciiprocessResources Gradle 任务。但我的 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 使用 UTF-8 编码加载我的 messages_de.properties 文件,因为它记录了以下消息。

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

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

有什么线索吗?

【问题讨论】:

  • 我也有同样的问题,在 Github 上打开了 grails-core 的问题:github.com/grails/grails-core/issues/10832
  • 我注意到这个问题只适用于我在 IntelliJ 中打开 Grails 项目时使用 gradlew clean build 构建我的战争。如果我在使用 Gradle 构建之前关闭 IntelliJ,一切都会按预期工作。奇怪的行为......

标签: grails internationalization grails-3.2


【解决方案1】:

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

resources.groovy 中,将 defaultEncoding 设置为 'UTF-8' 以用于 messageSource bean。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-09
    相关资源
    最近更新 更多