diff --git a/kord-extensions/src/main/kotlin/dev/kordex/core/commands/application/slash/SlashCommandParser.kt b/kord-extensions/src/main/kotlin/dev/kordex/core/commands/application/slash/SlashCommandParser.kt index 976112e641..c05ed69e34 100644 --- a/kord-extensions/src/main/kotlin/dev/kordex/core/commands/application/slash/SlashCommandParser.kt +++ b/kord-extensions/src/main/kotlin/dev/kordex/core/commands/application/slash/SlashCommandParser.kt @@ -20,7 +20,7 @@ import dev.kordex.core.commands.Arguments import dev.kordex.core.commands.converters.* import dev.kordex.core.commands.getDefaultTranslatedDisplayName import dev.kordex.core.i18n.generated.CoreTranslations -import dev.kordex.core.utils.withContext +import dev.kordex.core.i18n.withContext import io.github.oshai.kotlinlogging.KotlinLogging private val logger = KotlinLogging.logger {} diff --git a/kord-extensions/src/main/kotlin/dev/kordex/core/commands/chat/ChatCommandParser.kt b/kord-extensions/src/main/kotlin/dev/kordex/core/commands/chat/ChatCommandParser.kt index e106f8b4c2..783f9db8db 100644 --- a/kord-extensions/src/main/kotlin/dev/kordex/core/commands/chat/ChatCommandParser.kt +++ b/kord-extensions/src/main/kotlin/dev/kordex/core/commands/chat/ChatCommandParser.kt @@ -25,9 +25,9 @@ import dev.kordex.core.commands.converters.types.MultiNamedInputConverter import dev.kordex.core.commands.converters.types.SingleNamedInputConverter import dev.kordex.core.commands.getDefaultTranslatedDisplayName import dev.kordex.core.i18n.generated.CoreTranslations +import dev.kordex.core.i18n.withContext import dev.kordex.core.koin.KordExKoinComponent import dev.kordex.core.utils.MutableStringKeyedMap -import dev.kordex.core.utils.withContext import dev.kordex.parser.StringParser import io.github.oshai.kotlinlogging.KotlinLogging import org.koin.core.component.inject diff --git a/kord-extensions/src/main/kotlin/dev/kordex/core/commands/converters/Converter.kt b/kord-extensions/src/main/kotlin/dev/kordex/core/commands/converters/Converter.kt index bfe427abd2..a28ff05a92 100644 --- a/kord-extensions/src/main/kotlin/dev/kordex/core/commands/converters/Converter.kt +++ b/kord-extensions/src/main/kotlin/dev/kordex/core/commands/converters/Converter.kt @@ -17,8 +17,8 @@ import dev.kordex.core.commands.CommandContext import dev.kordex.core.commands.converters.builders.ConverterBuilder import dev.kordex.core.commands.converters.builders.ValidationContext import dev.kordex.core.i18n.types.Key +import dev.kordex.core.i18n.withContext import dev.kordex.core.koin.KordExKoinComponent -import dev.kordex.core.utils.withContext import dev.kordex.parser.StringParser import org.koin.core.component.inject import kotlin.reflect.KProperty diff --git a/kord-extensions/src/main/kotlin/dev/kordex/core/i18n/_Utils.kt b/kord-extensions/src/main/kotlin/dev/kordex/core/i18n/_Utils.kt index 80ecba164d..df4b53d08f 100644 --- a/kord-extensions/src/main/kotlin/dev/kordex/core/i18n/_Utils.kt +++ b/kord-extensions/src/main/kotlin/dev/kordex/core/i18n/_Utils.kt @@ -11,6 +11,7 @@ package dev.kordex.core.i18n import dev.kordex.core.i18n.types.Bundle import dev.kordex.core.i18n.types.Key import dev.kordex.core.i18n.types.PlaceholderPosition +import dev.kordex.core.types.TranslatableContext import java.util.Locale private val translationKeyMap: MutableMap = mutableMapOf() @@ -49,3 +50,6 @@ public fun String.toKey(bundle: Bundle): Key = public fun String.toKey(bundle: String): Key = toKey(Bundle(bundle)) + +public suspend fun Key.withContext(context: TranslatableContext) = + withLocale(context.getLocale()) diff --git a/kord-extensions/src/main/kotlin/dev/kordex/core/i18n/types/Key.kt b/kord-extensions/src/main/kotlin/dev/kordex/core/i18n/types/Key.kt index 9be3e7f57e..125f2439f0 100644 --- a/kord-extensions/src/main/kotlin/dev/kordex/core/i18n/types/Key.kt +++ b/kord-extensions/src/main/kotlin/dev/kordex/core/i18n/types/Key.kt @@ -25,7 +25,7 @@ public data class Key( @Serializable(with = LocaleSerializer::class) public val locale: Locale? = null, - public val presetPlaceholderPosition: PlaceholderPosition = PlaceholderPosition.START, + public val presetPlaceholderPosition: PlaceholderPosition = PlaceholderPosition.FIRST, public val translateNestedKeys: Boolean = true, @Transient @@ -58,6 +58,9 @@ public data class Key( public fun withNamedPlaceholders(vararg placeholders: Pair): Key = copy(namedPlaceholders = namedPlaceholders + placeholders) + public fun withNamedPlaceholders(placeholders: Map): Key = + copy(namedPlaceholders = placeholders + placeholders) + public fun withPresetPlaceholderPosition(position: PlaceholderPosition): Key = copy(presetPlaceholderPosition = position) @@ -131,8 +134,8 @@ public data class Key( public fun translateArray(replacements: Array): String { val allReplacements = when (presetPlaceholderPosition) { - PlaceholderPosition.START -> ordinalPlaceholders + replacements - PlaceholderPosition.END -> replacements.asList() + ordinalPlaceholders + PlaceholderPosition.FIRST -> ordinalPlaceholders + replacements + PlaceholderPosition.LAST -> replacements.asList() + ordinalPlaceholders }.map { if (translateNestedKeys && it is Key) { it @@ -149,8 +152,8 @@ public data class Key( public fun translateNamed(replacements: Map): String { val allReplacements = when (presetPlaceholderPosition) { - PlaceholderPosition.START -> namedPlaceholders + replacements - PlaceholderPosition.END -> replacements + namedPlaceholders + PlaceholderPosition.FIRST -> namedPlaceholders + replacements + PlaceholderPosition.LAST -> replacements + namedPlaceholders }.mapValues { if (translateNestedKeys && it.value is Key) { (it.value as Key) diff --git a/kord-extensions/src/main/kotlin/dev/kordex/core/i18n/types/PlaceholderPosition.kt b/kord-extensions/src/main/kotlin/dev/kordex/core/i18n/types/PlaceholderPosition.kt index 7efa999472..6baee92381 100644 --- a/kord-extensions/src/main/kotlin/dev/kordex/core/i18n/types/PlaceholderPosition.kt +++ b/kord-extensions/src/main/kotlin/dev/kordex/core/i18n/types/PlaceholderPosition.kt @@ -12,6 +12,6 @@ import kotlinx.serialization.Serializable @Serializable public enum class PlaceholderPosition { - START, - END + FIRST, + LAST } diff --git a/kord-extensions/src/main/kotlin/dev/kordex/core/utils/_i18n.kt b/kord-extensions/src/main/kotlin/dev/kordex/core/utils/_i18n.kt deleted file mode 100644 index 9ec4aa3473..0000000000 --- a/kord-extensions/src/main/kotlin/dev/kordex/core/utils/_i18n.kt +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyrighted (Kord Extensions, 2024). Licensed under the EUPL-1.2 - * with the specific provision (EUPL articles 14 & 15) that the - * applicable law is the (Republic of) Irish law and the Jurisdiction - * Dublin. - * Any redistribution must include the specific provision above. - */ - -package dev.kordex.core.utils - -import dev.kordex.core.i18n.types.Key -import dev.kordex.core.types.TranslatableContext - -public suspend fun Key.withContext(context: TranslatableContext) = - withLocale(context.getLocale()) diff --git a/modules/dev/dev-java-time/src/main/kotlin/dev/kordex/modules/dev/java/time/J8DurationCoalescingConverter.kt b/modules/dev/dev-java-time/src/main/kotlin/dev/kordex/modules/dev/java/time/J8DurationCoalescingConverter.kt index a3c0790854..a83ece6e72 100644 --- a/modules/dev/dev-java-time/src/main/kotlin/dev/kordex/modules/dev/java/time/J8DurationCoalescingConverter.kt +++ b/modules/dev/dev-java-time/src/main/kotlin/dev/kordex/modules/dev/java/time/J8DurationCoalescingConverter.kt @@ -23,9 +23,9 @@ import dev.kordex.core.commands.wrapOption import dev.kordex.core.i18n.EMPTY_VALUE_STRING import dev.kordex.core.i18n.generated.CoreTranslations import dev.kordex.core.i18n.types.Key +import dev.kordex.core.i18n.withContext import dev.kordex.core.parsers.DurationParserException import dev.kordex.core.parsers.InvalidTimeUnitException -import dev.kordex.core.utils.withContext import dev.kordex.parser.StringParser import dev.kordex.parser.tokens.PositionalArgumentToken import io.github.oshai.kotlinlogging.KLogger diff --git a/modules/dev/dev-java-time/src/main/kotlin/dev/kordex/modules/dev/java/time/J8DurationConverter.kt b/modules/dev/dev-java-time/src/main/kotlin/dev/kordex/modules/dev/java/time/J8DurationConverter.kt index fce0928e38..15f1c92a22 100644 --- a/modules/dev/dev-java-time/src/main/kotlin/dev/kordex/modules/dev/java/time/J8DurationConverter.kt +++ b/modules/dev/dev-java-time/src/main/kotlin/dev/kordex/modules/dev/java/time/J8DurationConverter.kt @@ -22,9 +22,9 @@ import dev.kordex.core.commands.converters.Validator import dev.kordex.core.commands.wrapOption import dev.kordex.core.i18n.generated.CoreTranslations import dev.kordex.core.i18n.types.Key +import dev.kordex.core.i18n.withContext import dev.kordex.core.parsers.DurationParserException import dev.kordex.core.parsers.InvalidTimeUnitException -import dev.kordex.core.utils.withContext import dev.kordex.parser.StringParser import java.time.Duration import java.time.LocalDateTime diff --git a/modules/dev/dev-time4j/src/main/kotlin/dev/kordex/modules/dev/time4j/T4JDurationCoalescingConverter.kt b/modules/dev/dev-time4j/src/main/kotlin/dev/kordex/modules/dev/time4j/T4JDurationCoalescingConverter.kt index 5941ed3d6e..3636fbdf18 100644 --- a/modules/dev/dev-time4j/src/main/kotlin/dev/kordex/modules/dev/time4j/T4JDurationCoalescingConverter.kt +++ b/modules/dev/dev-time4j/src/main/kotlin/dev/kordex/modules/dev/time4j/T4JDurationCoalescingConverter.kt @@ -23,9 +23,9 @@ import dev.kordex.core.commands.wrapOption import dev.kordex.core.i18n.EMPTY_VALUE_STRING import dev.kordex.core.i18n.generated.CoreTranslations import dev.kordex.core.i18n.types.Key +import dev.kordex.core.i18n.withContext import dev.kordex.core.parsers.DurationParserException import dev.kordex.core.parsers.InvalidTimeUnitException -import dev.kordex.core.utils.withContext import dev.kordex.parser.StringParser import dev.kordex.parser.tokens.PositionalArgumentToken import io.github.oshai.kotlinlogging.KLogger diff --git a/modules/dev/dev-time4j/src/main/kotlin/dev/kordex/modules/dev/time4j/T4JDurationConverter.kt b/modules/dev/dev-time4j/src/main/kotlin/dev/kordex/modules/dev/time4j/T4JDurationConverter.kt index be2170f616..b20f3a752a 100644 --- a/modules/dev/dev-time4j/src/main/kotlin/dev/kordex/modules/dev/time4j/T4JDurationConverter.kt +++ b/modules/dev/dev-time4j/src/main/kotlin/dev/kordex/modules/dev/time4j/T4JDurationConverter.kt @@ -22,9 +22,9 @@ import dev.kordex.core.commands.converters.Validator import dev.kordex.core.commands.wrapOption import dev.kordex.core.i18n.generated.CoreTranslations import dev.kordex.core.i18n.types.Key +import dev.kordex.core.i18n.withContext import dev.kordex.core.parsers.DurationParserException import dev.kordex.core.parsers.InvalidTimeUnitException -import dev.kordex.core.utils.withContext import dev.kordex.parser.StringParser import net.time4j.Duration import net.time4j.IsoUnit diff --git a/modules/dev/dev-unsafe/src/main/kotlin/dev/kordex/modules/dev/unsafe/converters/UnionConverter.kt b/modules/dev/dev-unsafe/src/main/kotlin/dev/kordex/modules/dev/unsafe/converters/UnionConverter.kt index bc3be7cfc6..924d17cd57 100644 --- a/modules/dev/dev-unsafe/src/main/kotlin/dev/kordex/modules/dev/unsafe/converters/UnionConverter.kt +++ b/modules/dev/dev-unsafe/src/main/kotlin/dev/kordex/modules/dev/unsafe/converters/UnionConverter.kt @@ -27,7 +27,7 @@ import dev.kordex.core.commands.wrapOption import dev.kordex.core.i18n.generated.CoreTranslations import dev.kordex.core.i18n.toKey import dev.kordex.core.i18n.types.Key -import dev.kordex.core.utils.withContext +import dev.kordex.core.i18n.withContext import dev.kordex.modules.dev.unsafe.annotations.UnsafeAPI import dev.kordex.parser.StringParser diff --git a/modules/functionality/func-mappings/src/main/kotlin/dev/kordex/modules/func/mappings/MappingsExtension.kt b/modules/functionality/func-mappings/src/main/kotlin/dev/kordex/modules/func/mappings/MappingsExtension.kt index 881a3d4894..6e1fb75aa3 100644 --- a/modules/functionality/func-mappings/src/main/kotlin/dev/kordex/modules/func/mappings/MappingsExtension.kt +++ b/modules/functionality/func-mappings/src/main/kotlin/dev/kordex/modules/func/mappings/MappingsExtension.kt @@ -34,6 +34,7 @@ import dev.kordex.core.extensions.publicSlashCommand import dev.kordex.core.i18n.EMPTY_KEY import dev.kordex.core.i18n.toKey import dev.kordex.core.i18n.types.Key +import dev.kordex.core.i18n.withContext import dev.kordex.core.pagination.EXPAND_EMOJI import dev.kordex.core.pagination.PublicResponsePaginator import dev.kordex.core.pagination.pages.Page @@ -41,7 +42,6 @@ import dev.kordex.core.pagination.pages.Pages import dev.kordex.core.sentry.BreadcrumbType import dev.kordex.core.storage.StorageType import dev.kordex.core.storage.StorageUnit -import dev.kordex.core.utils.withContext import dev.kordex.modules.func.mappings.arguments.* import dev.kordex.modules.func.mappings.builders.ExtMappingsBuilder import dev.kordex.modules.func.mappings.enums.Channels