Skip to content

Commit 3c04355

Browse files
committed
fallback actually works now
1 parent e058b1d commit 3c04355

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/block/PylonBlock.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import io.github.pylonmc.pylon.core.block.waila.WailaConfig
77
import io.github.pylonmc.pylon.core.config.Config
88
import io.github.pylonmc.pylon.core.config.Settings
99
import io.github.pylonmc.pylon.core.datatypes.PylonSerializers
10+
import io.github.pylonmc.pylon.core.i18n.AddonTranslator
1011
import io.github.pylonmc.pylon.core.registry.PylonRegistry
1112
import io.github.pylonmc.pylon.core.util.position.BlockPosition
1213
import io.github.pylonmc.pylon.core.util.position.position
@@ -30,8 +31,7 @@ open class PylonBlock protected constructor(val block: Block) {
3031
@JvmSynthetic
3132
internal var errorBlock: BlockDisplay? = null
3233

33-
// doesn't work yet
34-
open val name: Component = Component.translatable("pylon.${schema.key.namespace}.item.${schema.key.key}.waila", Component.translatable("pylon.${schema.key.namespace}.item.${schema.key.key}.name"))
34+
open val name: Component = Component.translatable("pylon.${schema.key.namespace}.item.${schema.key.key}.waila", "pylon.${schema.key.namespace}.item.${schema.key.key}.name")
3535

3636
constructor(block: Block, context: BlockCreateContext) : this(block)
3737
constructor(block: Block, pdc: PersistentDataContainer) : this(block)

pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/i18n/AddonTranslator.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import net.kyori.adventure.text.Component
88
import net.kyori.adventure.text.TextReplacementConfig
99
import net.kyori.adventure.text.TranslatableComponent
1010
import net.kyori.adventure.text.VirtualComponent
11+
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer
1112
import net.kyori.adventure.translation.GlobalTranslator
1213
import net.kyori.adventure.translation.Translator
1314
import org.apache.commons.lang3.LocaleUtils
@@ -37,7 +38,14 @@ class AddonTranslator(private val addon: PylonAddon) : Translator {
3738
override fun translate(key: String, locale: Locale): MessageFormat? = null
3839

3940
override fun translate(component: TranslatableComponent, locale: Locale): Component? {
40-
var translated = getTranslation(component, locale) ?: return null
41+
var translated = getTranslation(component, locale).let {
42+
if (it == null) {
43+
val fallback = component.fallback()
44+
if (fallback != null) {
45+
getTranslation(fallback, locale) ?: return null
46+
} else return null
47+
} else it
48+
}
4149
for (arg in component.arguments()) {
4250
val component = arg.asComponent()
4351
if (component !is VirtualComponent) continue
@@ -75,7 +83,7 @@ class AddonTranslator(private val addon: PylonAddon) : Translator {
7583
}
7684

7785
fun translationKeyExists(key: String, locale: Locale): Boolean
78-
= getTranslation(key, locale) != null
86+
= getTranslation(key, locale) != null
7987

8088
companion object : Listener {
8189

0 commit comments

Comments
 (0)