mirror of
https://github.com/EngineHub/WorldEdit.git
synced 2025-01-30 12:51:17 +08:00
Add incremental translation checker
Only validates basic formatting, not number of arguments.
This commit is contained in:
parent
957af4962e
commit
3a3686289f
43
buildSrc/src/main/kotlin/TranslationFileCheck.kt
Normal file
43
buildSrc/src/main/kotlin/TranslationFileCheck.kt
Normal file
@ -0,0 +1,43 @@
|
||||
import groovy.json.JsonSlurper
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.file.ConfigurableFileCollection
|
||||
import org.gradle.api.file.FileType
|
||||
import org.gradle.api.tasks.InputFiles
|
||||
import org.gradle.api.tasks.PathSensitive
|
||||
import org.gradle.api.tasks.PathSensitivity
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
import org.gradle.work.ChangeType
|
||||
import org.gradle.work.Incremental
|
||||
import org.gradle.work.InputChanges
|
||||
import java.text.MessageFormat
|
||||
|
||||
@Suppress("UnstableApiUsage")
|
||||
abstract class TranslationFileCheck : DefaultTask() {
|
||||
|
||||
@get:[
|
||||
Incremental
|
||||
PathSensitive(PathSensitivity.NONE)
|
||||
InputFiles
|
||||
]
|
||||
abstract val translationFiles: ConfigurableFileCollection
|
||||
|
||||
@TaskAction
|
||||
fun checkTranslationFiles(inputChanges: InputChanges) {
|
||||
inputChanges.getFileChanges(translationFiles)
|
||||
.asSequence()
|
||||
.filter { it.fileType != FileType.DIRECTORY }
|
||||
.filter { it.changeType != ChangeType.REMOVED }
|
||||
.forEach { change ->
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val entries = JsonSlurper().parse(change.file) as Map<String, String>
|
||||
for ((key, value) in entries) {
|
||||
try {
|
||||
MessageFormat(value)
|
||||
} catch (e: IllegalArgumentException) {
|
||||
error("Entry '$key' in ${change.file} is an invalid translation file: ${e.message}")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -83,20 +83,20 @@
|
||||
}
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
main {
|
||||
java {
|
||||
srcDir("src/main/java")
|
||||
srcDir("src/legacy/java")
|
||||
}
|
||||
resources {
|
||||
srcDir("src/main/resources")
|
||||
}
|
||||
sourceSets.named("main") {
|
||||
java {
|
||||
srcDir("src/main/java")
|
||||
srcDir("src/legacy/java")
|
||||
}
|
||||
resources {
|
||||
srcDir("src/main/resources")
|
||||
}
|
||||
}
|
||||
|
||||
val crowdinApiKey = "crowdin_apikey"
|
||||
val i18nSource = file("src/main/resources/lang/strings.json")
|
||||
val processResources = tasks.named<Copy>("processResources")
|
||||
|
||||
val crowdinApiKey = "crowdin_apikey"
|
||||
if (project.hasProperty(crowdinApiKey) && !gradle.startParameter.isOffline) {
|
||||
tasks.named<UploadSourceFileTask>("crowdinUpload") {
|
||||
apiKey = "${project.property(crowdinApiKey)}"
|
||||
@ -104,7 +104,7 @@
|
||||
files = arrayOf(
|
||||
object {
|
||||
var name = "strings.json"
|
||||
var source = "${file("src/main/resources/lang/strings.json")}"
|
||||
var source = "$i18nSource"
|
||||
}
|
||||
)
|
||||
}
|
||||
@ -115,14 +115,25 @@
|
||||
projectId = "worldedit-core"
|
||||
}
|
||||
|
||||
tasks.named<Copy>("processResources") {
|
||||
processResources.configure {
|
||||
dependsOn(dlTranslationsTask)
|
||||
from(dlTranslationsTask.get().destination) {
|
||||
from(dlTranslationsTask.map { it.destination }) {
|
||||
into("lang")
|
||||
}
|
||||
}
|
||||
|
||||
tasks.named("classes").configure {
|
||||
tasks.named("classes") {
|
||||
dependsOn("crowdinDownload")
|
||||
}
|
||||
}
|
||||
|
||||
// allow checking of the source file even without the API key
|
||||
val checkTranslationFiles by tasks.registering(TranslationFileCheck::class) {
|
||||
dependsOn(processResources)
|
||||
translationFiles.from(fileTree(processResources.map { it.destinationDir }) {
|
||||
include("**/lang/**/*.json")
|
||||
})
|
||||
}
|
||||
tasks.named("check") {
|
||||
dependsOn(checkTranslationFiles)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user