From b74d46101b66dc3b41c3fce8a835d079b1466b24 Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Sun, 8 Dec 2019 22:40:29 +0000 Subject: [PATCH] Fix #1875 --- build.gradle | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 36525cc40..8f180f0d5 100644 --- a/build.gradle +++ b/build.gradle @@ -134,7 +134,7 @@ jar { classifier = 'universal' from { crowdin.getDidWork() ? fileTree('build/translations').matching{exclude "**/en_US.json"} : null} - dependsOn 'renameCrowdin' + dependsOn 'fixTranslations' } @@ -171,6 +171,26 @@ task renameCrowdin(type: Copy, dependsOn: ['crowdin', 'cleanCrowdin']){ rename { String filename -> return filename.toLowerCase() } + doFirst { + file('build/translations').deleteDir() + } +} + +import groovy.json.JsonSlurper +import groovy.json.JsonOutput + +//Remove all translations that do not have an entry, ensures that minecraft falls back to EN_US over writing out an empty string. +task fixTranslations(dependsOn: ['renameCrowdin']) { + def jsonSlurper = new JsonSlurper() + doLast { + file('build/translations').eachFileRecurse(groovy.io.FileType.FILES) { + if(it.name.endsWith(".json")) { + def lang = jsonSlurper.parseText(it.text) + lang.values().removeIf { val -> val.empty} + it.text = JsonOutput.prettyPrint(JsonOutput.toJson(lang)) + } + } + } } task sourcesJar(type: Jar, dependsOn: classes) {