[英]How to automatically escape unicode characters in Java property files using Gradle?
I'm translating a Java application by using a ResourceBundle
with various *.properties
files. 我正在使用带有各种
*.properties
文件的ResourceBundle
来翻译Java应用程序。 Now I like to have a Gradle task or want to modify a task to automatically escape any unicode character by replacing it with its ASCII representation, something like Java's native2ascii
tool does. 现在我想要一个Gradle任务,或者想要修改一个任务,通过用它的ASCII表示替换它来自动转义任何unicode字符,就像Java的
native2ascii
工具那样。
This is what I'm done so far with my build file, but the output remains unescaped : 这是我到目前为止使用我的构建文件所做的,但输出仍未转义 :
import org.apache.tools.ant.filters.EscapeUnicode
tasks.withType(ProcessResources) {
filesMatching('**/*.properties') {
println "\t-> ${it}"
filter EscapeUnicode
}
}
Any help is appreciated. 任何帮助表示赞赏。
You can do it providing the additional copy specification for properties files, this way: 您可以通过以下方式为属性文件提供额外的复制规范:
import org.apache.tools.ant.filters.EscapeUnicode
tasks.withType(ProcessResources).each { task ->
task.from(task.getSource()) {
include '**/*.properties'
filter(EscapeUnicode)
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.