Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Directly save the translated file from GetLocalization #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,36 @@ class GetLocalizationDownloadTask extends DefaultTask {
}

// Dump translation
def translatedData = new XmlParser().parse(fetchURI(url))
def br = fetchURI(url)

tmpFile.withWriter("UTF-8") { out ->
out.print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
String line
while ((line = br.readLine()) != null) {
out.println line
}
out.print String.format("<!-- Translation '%s'->%s, progress %s%%, master '%s' -->\n",
t.iana_code, codes, t.progress, t.master_file)
out.print "<resources>\n"
translatedData.string.each { s ->
def String text = s.text()
.replaceAll("&", "&amp;")
.replaceAll("([^\\\\])'", "\\1\\'")
.replaceAll("\\.\\.\\.", "&#8230;")
.replaceAll("<", "&lt;")
.replaceAll(">", "&gt;")
out.print String.format(" <string name=\"%s\">%s</string>\n", s.'@name', text)
}

// For each code check target dir and copy file over
codes.each { code ->
def File targetDir = new File(resDir, String.format("values-%s", code.trim()))
if (!targetDir.exists()) targetDir.mkdir()
if (!targetDir.exists() || !targetDir.isDirectory()) {
throw new IOException(
"Target translation directory cannot be created"
)
}
out.print "</resources>\n"

// Copy (JAVA 7 or newer only)
File targetFile = new File(targetDir, t.filename.replaceAll(".*/", ""))
Files.copy(tmpFile.toPath(), targetFile.toPath(), StandardCopyOption.REPLACE_EXISTING)
}

// All done
tmpFile.delete()
}

// For each code check target dir and copy file over
codes.each { code ->
def File targetDir = new File(resDir, String.format("values-%s", code.trim()))
Expand Down