From 334d582c0ced07f59aec99d02d12b72cc3853e33 Mon Sep 17 00:00:00 2001 From: Jonas Herzig Date: Mon, 12 Aug 2024 10:58:01 +0200 Subject: [PATCH] Standalone: Implement UI18n --- .../kotlin/gg/essential/universal/UI18n.kt | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/gg/essential/universal/UI18n.kt b/src/main/kotlin/gg/essential/universal/UI18n.kt index 00dc452..603de19 100644 --- a/src/main/kotlin/gg/essential/universal/UI18n.kt +++ b/src/main/kotlin/gg/essential/universal/UI18n.kt @@ -1,6 +1,8 @@ package gg.essential.universal //#if STANDALONE +//$$ import java.util.ServiceLoader +//$$ import java.util.IllegalFormatException //#else import net.minecraft.client.resources.I18n //#endif @@ -8,9 +10,24 @@ import net.minecraft.client.resources.I18n object UI18n { fun i18n(key: String, vararg arguments: Any?): String { //#if STANDALONE - //$$ TODO("i18n($key, $arguments)") + //$$ return theProvider.i18n(key, *arguments) //#else return I18n.format(key, *arguments) //#endif } + + //#if STANDALONE + //$$ private val theProvider = ServiceLoader.load(Provider::class.java).firstOrNull() ?: FallbackProvider + //$$ interface Provider { + //$$ fun i18n(key: String, vararg arguments: Any?): String + //$$ } + //$$ private object FallbackProvider : Provider { + //$$ override fun i18n(key: String, vararg arguments: Any?): String = try { + //$$ String.format(key, *arguments) + //$$ } catch (e: IllegalFormatException) { + //$$ e.printStackTrace() + //$$ "[format error $key]" + //$$ } + //$$ } + //#endif }