Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: gradle task verifyI18nJsonKeys #5176

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,47 @@ task detektProjectBaseline(type: io.gitlab.arturbosch.detekt.DetektCreateBaselin
exclude("**/build/**")
}

tasks.register("verifyI18nJsonKeys") {
def baselineFileName = "en_us.json"

group = "verification"
description = "Compare i18n JSON files with ${baselineFileName} as the baseline and report missing keys."

def i18nDir = file("src/main/resources/resources/liquidbounce/lang")

doLast {
if (!i18nDir.exists() || !i18nDir.isDirectory()) {
throw new GradleException("The specified directory ${i18nDir} does not exist or is not a directory.")
}

def baselineFile = new File(i18nDir, baselineFileName)
if (!baselineFile.exists()) {
throw new GradleException("Baseline file ${baselineFileName} not found in ${i18nDir}.")
}

def baseline = new JsonSlurper().parse(baselineFile)

i18nDir.eachFile { file ->
if (file.name.endsWith(".json") && file.name != baselineFileName) {
def currentFile = new JsonSlurper().parse(file)

def missingKeys = baseline.keySet() - currentFile.keySet()

if (missingKeys.isEmpty()) {
println "${file.name} is complete. No missing keys."
} else {
def limitedMissingKeys = missingKeys.take(5)
def output = limitedMissingKeys.join(', ')
if (missingKeys.size() > 5) {
output += ", ..."
}
println "${file.name} is missing the following keys (${missingKeys.size()}): ${output}"
}
}
}
}
}

java {
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present.
Expand Down
Loading