aboutsummaryrefslogtreecommitdiff
path: root/example/src/main/kotlin
diff options
context:
space:
mode:
Diffstat (limited to 'example/src/main/kotlin')
-rw-r--r--example/src/main/kotlin/OtherTest.kt6
-rw-r--r--example/src/main/kotlin/Test2.kt5
-rw-r--r--example/src/main/kotlin/test.kt7
3 files changed, 16 insertions, 2 deletions
diff --git a/example/src/main/kotlin/OtherTest.kt b/example/src/main/kotlin/OtherTest.kt
new file mode 100644
index 0000000..fe31a16
--- /dev/null
+++ b/example/src/main/kotlin/OtherTest.kt
@@ -0,0 +1,6 @@
+package moe.nea.mcautotranslations.example
+
+class OtherTest {
+
+ fun testFunc(x: Int, y: Text) = tr("other-test.test-func", "Hello $y: $x")
+}
diff --git a/example/src/main/kotlin/Test2.kt b/example/src/main/kotlin/Test2.kt
new file mode 100644
index 0000000..40d23db
--- /dev/null
+++ b/example/src/main/kotlin/Test2.kt
@@ -0,0 +1,5 @@
+package moe.nea.mcautotranslations.example
+
+object Test2 {
+ fun x() = tr("test2.object", "Hehheehe")
+}
diff --git a/example/src/main/kotlin/test.kt b/example/src/main/kotlin/test.kt
index cb5ddfa..c5132d4 100644
--- a/example/src/main/kotlin/test.kt
+++ b/example/src/main/kotlin/test.kt
@@ -10,15 +10,18 @@ val resources =
class Text(val key: String, val args: Array<out Any>) {
override fun toString(): String {
- return resources[key]!!.format(*args)
+ return (resources[key] ?: error("Unresolved key $key")).format(*args)
}
}
@Suppress("UNUSED")
fun trResolved(key: String, vararg args: Any) = Text(key, args)
-fun tr(key: String, default: String): Text = error("Did not run compiler plugin")
+@Suppress("UNUSED")
+fun tr(key: String, default: String): Text = error("Did not run compiler plugin for key '$key' with default '$default'")
fun main() {
println(tr("test1", "Hiiiiiii"))
println(tr("test2", "Hello ${Math.random()}"))
println(tr("test3", "Goodbye ${Math.random()} ${Math.E}"))
+ println(OtherTest().testFunc(10, tr("lol", "Lolnea")))
+ println(Test2.x())
}