Skip to content

Commit

Permalink
Add compare lang files task
Browse files Browse the repository at this point in the history
  • Loading branch information
mchorse committed Jul 8, 2020
1 parent 7e2323c commit c9c4156
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,82 @@ task sourcesJar(type: Jar) {
artifacts {
archives deobfJar
archives sourcesJar
}

/* Comparing keys */
task compareLangFiles {
doLast {
def help = file("src/main/resources/assets/${project.archivesBaseName}/lang/")
def parse = { File file ->
def map = new HashMap()
def splits = file.text.split("\n");

for (split in splits) {
def index = split.indexOf("=")

if (index == -1) {
continue
}

map.put(split.substring(0, index), true)
}

return map
}

if (!help.exists()) {
return
}

def en = file("${help.getAbsolutePath()}/en_US.lang")
def en_map = parse(en)

for (lang_file in help.listFiles()) {
if (!lang_file.name.endsWith(".lang") || lang_file.name.startsWith("en_US")) {
continue
}

def lang_map = parse(lang_file)
def missing = new ArrayList()
def extra = new ArrayList()

for (key in en_map.keySet()) {
if (!lang_map.containsKey(key)) {
missing.add(key)
}
}

for (key in lang_map.keySet()) {
if (!en_map.containsKey(key)) {
extra.add(key)
}
}

missing.sort()
extra.sort()

print("\n")

if (!missing.isEmpty() || !extra.isEmpty()) {
if (!missing.isEmpty()) {
print("Language file ${lang_file.getName()} misses following keys:\n")

for (key in missing) {
print("- ${key}\n")
}
}

if (!extra.isEmpty()) {
print("Language file ${lang_file.getName()} has additional keys:\n")

for (key in extra) {
print("- ${key}\n")
}
}
}
else {
print("Language file ${lang_file.getName()} fully matches ${en.getName()}!\n")
}
}
}
}

0 comments on commit c9c4156

Please sign in to comment.