Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import io.github.pylonmc.pylon.core.event.PylonRegisterEvent
import io.github.pylonmc.pylon.core.event.PylonUnregisterEvent
import io.github.pylonmc.pylon.core.i18n.PylonTranslator.Companion.translator
import io.github.pylonmc.pylon.core.i18n.wrapping.LineWrapEncoder
import io.github.pylonmc.pylon.core.item.PylonItem
import io.github.pylonmc.pylon.core.item.builder.customMiniMessage
import io.github.pylonmc.pylon.core.nms.NmsAccessor
import io.github.pylonmc.pylon.core.registry.PylonRegistry
Expand Down Expand Up @@ -176,9 +177,11 @@ class PylonTranslator private constructor(private val addon: PylonAddon) : Trans
@JvmName("translateItem")
@Suppress("UnstableApiUsage")
fun ItemStack.translate(locale: Locale, arguments: List<PylonArgument> = emptyList()) {
val item = PylonItem.fromStack(this)
val usedArguments = item?.getPlaceholders() ?: arguments

editData(DataComponentTypes.ITEM_NAME) {
val translated = GlobalTranslator.render(it.withArguments(arguments), locale)
val translated = GlobalTranslator.render(it.withArguments(usedArguments), locale)
if (translated is TranslatableComponent && translated.fallback() != null) {
Component.text(translated.fallback()!!)
} else {
Expand All @@ -187,7 +190,7 @@ class PylonTranslator private constructor(private val addon: PylonAddon) : Trans
}
editData(DataComponentTypes.LORE) { lore ->
val newLore = lore.lines().flatMap { line ->
val translated = GlobalTranslator.render(line.withArguments(arguments), locale)
val translated = GlobalTranslator.render(line.withArguments(usedArguments), locale)
val encoded = LineWrapEncoder.encode(translated)
val wrapped = encoded.copy(
lines = encoded.lines.flatMap { wrapText(it, PylonConfig.translationWrapLimit) }
Expand Down
Loading