Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save john-stemberger/ac09e0694195f2b2a6e3a880ffc81a35 to your computer and use it in GitHub Desktop.
Save john-stemberger/ac09e0694195f2b2a6e3a880ffc81a35 to your computer and use it in GitHub Desktop.
helpful gradle scripts for verifying android translations
def printNode(Node xml) {
def s = new StringWriter()
PrintWriter printWriter = new PrintWriter(s);
XmlNodePrinter printer = new XmlNodePrinter(printWriter, " ");
printer.preserveWhitespace = true
printer.print(xml)
return s.toString();
}
task validateUSStrings<< {
File projectRoot = new File(".");
FileTree languageFiles = fileTree(dir: projectRoot.getAbsolutePath() + "/app/src/main");
languageFiles.include '**/values/*_strings.xml'
languageFiles.each { File file ->
def xmlParser = new XmlParser();
Node enXML = xmlParser.parse(file);
String usFileName = file.getAbsolutePath().replace("values", "values-en-rUS")
File usFile = new File(usFileName);
Node usXML = xmlParser.parse(usFile);
for (Node n : enXML.children())
{
for(Node usN: usXML.children())
{
if(usN.attribute("name") == n.attribute("name") && usN.text() == n.text())
{
usXML.remove(usN);
break;
}
}
}
if(usXML.children().size() > 0)
{
logger.lifecycle(usFile.getAbsolutePath() + ":\n" + printNode(enXML));
logger.lifecycle(usFile.getAbsolutePath() + ":\n" + printNode(usXML));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment