diff options
Diffstat (limited to 'example')
-rw-r--r-- | example/build.gradle.kts | 9 | ||||
-rw-r--r-- | example/src/main/kotlin/test.kt | 16 |
2 files changed, 21 insertions, 4 deletions
diff --git a/example/build.gradle.kts b/example/build.gradle.kts index b3f0a88..99b62f9 100644 --- a/example/build.gradle.kts +++ b/example/build.gradle.kts @@ -9,14 +9,19 @@ repositories { mavenCentral() } +dependencies { + implementation("com.google.code.gson:gson:2.11.0") +} + mcAutoTranslations { translationFunction.set("moe.nea.mcautotranslations.example.tr") translationFunctionResolved.set("moe.nea.mcautotranslations.example.trResolved") } -tasks.register("collectTranslations", CollectTranslations::class) { +val collectTranslations by tasks.registering(CollectTranslations::class) { this.baseTranslations.from(file("en_us.json")) this.classes.from(sourceSets.main.map { it.kotlin.classesDirectory }) - this.outputFile.set(layout.buildDirectory.file("compiled_en_us.json")) + this.outputFile.set(layout.buildDirectory.file("en_us.json")) } +tasks.processResources { from(collectTranslations) } diff --git a/example/src/main/kotlin/test.kt b/example/src/main/kotlin/test.kt index 291cdfe..7702dad 100644 --- a/example/src/main/kotlin/test.kt +++ b/example/src/main/kotlin/test.kt @@ -1,8 +1,20 @@ package moe.nea.mcautotranslations.example -data class Text(val key: String, val args: List<Any>) +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken -fun trResolved(key: String, vararg args: Any) = Text(key, args.toList()) +val resources = + Text::class.java.classLoader.getResourceAsStream("en_us.json")!!.reader().use { + Gson().fromJson(it, object : TypeToken<HashMap<String, String>>() {}) + } + +class Text(val key: String, val args: Array<out Any>) { + override fun toString(): String { + return resources[key]!!.format(*args) + } +} + +fun trResolved(key: String, vararg args: Any) = Text(key, args) fun tr(key: String, default: String): Text = error("Did not run compiler plugin") fun main() { println(tr("test1", "Hiiiiiii")) |