如何使用Gradle自动转义Java属性文件中的unicode字符?

时间:2016-06-09 15:10:18

标签: java gradle unicode properties-file

我正在使用ResourceBundle与各种*.properties文件翻译 Java 应用程序。现在,我希望有一个 Gradle 任务,或者希望修改任务以通过将其替换为 ASCII 表示来自动转义任何 unicode 字符。像Java的native2ascii工具那样。

这是我到目前为止使用构建文件完成的操作,但输出仍未转义

import org.apache.tools.ant.filters.EscapeUnicode

tasks.withType(ProcessResources) {
    filesMatching('**/*.properties') {
        println "\t-> ${it}"
        filter EscapeUnicode
    }
}

感谢任何帮助。

1 个答案:

答案 0 :(得分:4)

您可以通过以下方式为属性文件提供额外的复制规范:

import org.apache.tools.ant.filters.EscapeUnicode
tasks.withType(ProcessResources).each { task ->
    task.from(task.getSource()) {
        include '**/*.properties'
        filter(EscapeUnicode)
    }
}