Skip to content

Commit

Permalink
Standalone: Implement UI18n
Browse files Browse the repository at this point in the history
  • Loading branch information
Johni0702 committed Aug 12, 2024
1 parent 13c00ee commit 334d582
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/main/kotlin/gg/essential/universal/UI18n.kt
Original file line number Diff line number Diff line change
@@ -1,16 +1,33 @@
package gg.essential.universal

//#if STANDALONE
//$$ import java.util.ServiceLoader
//$$ import java.util.IllegalFormatException
//#else
import net.minecraft.client.resources.I18n
//#endif

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
}

0 comments on commit 334d582

Please sign in to comment.