Created
December 6, 2016 21:00
-
-
Save wlievens/8a137c530497ebeb99429760f2d3311e to your computer and use it in GitHub Desktop.
How to validate consistency of angular-translate (or other) json i18n files with groovy-maven-plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import groovy.json.JsonSlurper | |
log.info("Verifying JSON translation files ...") | |
def root = new File(sprintf('%s/src/main/resources/static/i18n/', project.basedir)) | |
def slurper = new JsonSlurper() | |
def allKeys = [] as Set | |
def tables = [:] | |
root.listFiles().each { | |
if (it.name.endsWith(".json")) { | |
def table = slurper.parse(it) | |
allKeys.addAll(table.keySet()) | |
tables[it] = table | |
} | |
} | |
def problem = false | |
tables.each { | |
def file = it.key | |
def table = it.value | |
def difference = allKeys - table.keySet() | |
difference.each { | |
log.error("File '{}' is missing key '{}'", file.name, it) | |
} | |
if (!difference.isEmpty()) | |
problem = true | |
} | |
if (problem) | |
throw new RuntimeException("I18N files are not consistent!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment