How to automatically escape unicode characters in

2019-04-28 02:53发布

问题:

I'm translating a Java application by using a ResourceBundle with various *.properties files. 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.

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.

回答1:

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)
    }
}