From 1eddb991edac58ec15dec5241eceb0d1197aac3e Mon Sep 17 00:00:00 2001 From: Alexander Oprisnik Date: Wed, 4 Feb 2015 13:26:22 +0100 Subject: [PATCH] Directly save the translated file from GetLocalization Save the whole translated XML file instead of parsing just the tags -> Plurals, comments, and all other tags are saved as well. --- .../gradle/GetLocalizationDownloadTask.groovy | 36 ++++++++++++------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/src/main/groovy/org/zooper/gradle/GetLocalizationDownloadTask.groovy b/src/main/groovy/org/zooper/gradle/GetLocalizationDownloadTask.groovy index 1daf7e2..db042d7 100755 --- a/src/main/groovy/org/zooper/gradle/GetLocalizationDownloadTask.groovy +++ b/src/main/groovy/org/zooper/gradle/GetLocalizationDownloadTask.groovy @@ -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 "\n" + String line + while ((line = br.readLine()) != null) { + out.println line + } out.print String.format("\n", t.iana_code, codes, t.progress, t.master_file) - out.print "\n" - translatedData.string.each { s -> - def String text = s.text() - .replaceAll("&", "&") - .replaceAll("([^\\\\])'", "\\1\\'") - .replaceAll("\\.\\.\\.", "…") - .replaceAll("<", "<") - .replaceAll(">", ">") - out.print String.format(" %s\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 "\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()))