diff --git a/gradle.properties b/gradle.properties index 2f4ee84e25..2ad4b45a95 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,9 +1,7 @@ #dokka will run out of memory with the default metaspace org.gradle.jvmargs=-XX:MaxMetaspaceSize=1024m org.gradle.parallel=true - kotlin.incremental=true ksp.incremental=false ksp.useKSP2=true - -projectVersion=2.2.0-SNAPSHOT +projectVersion=2.3.0-SNAPSHOT diff --git a/kord-extensions/src/main/kotlin/dev/kordex/core/builders/about/Section.kt b/kord-extensions/src/main/kotlin/dev/kordex/core/builders/about/Section.kt index 5d2dbd42c0..0fc107fb6a 100644 --- a/kord-extensions/src/main/kotlin/dev/kordex/core/builders/about/Section.kt +++ b/kord-extensions/src/main/kotlin/dev/kordex/core/builders/about/Section.kt @@ -30,7 +30,7 @@ public class Section(public val name: String, public val description: String) : } public fun translate(key: String, locale: Locale, replacements: Array = arrayOf()): String = - translations.translate(key, translationBundle, locale, replacements = replacements) + translations.translate(key = key, bundleName = translationBundle, locale = locale, replacements = replacements) public fun validate() { if (!::builder.isInitialized) { diff --git a/kord-extensions/src/main/kotlin/dev/kordex/core/checks/types/CheckContext.kt b/kord-extensions/src/main/kotlin/dev/kordex/core/checks/types/CheckContext.kt index 76104b881e..8b9cf986f8 100644 --- a/kord-extensions/src/main/kotlin/dev/kordex/core/checks/types/CheckContext.kt +++ b/kord-extensions/src/main/kotlin/dev/kordex/core/checks/types/CheckContext.kt @@ -171,7 +171,7 @@ public open class CheckContext( replacements: Array = arrayOf(), ): String = - translations.translate(key, locale, bundleName = bundle, replacements = replacements) + translations.translate(key = key, bundleName = bundle, locale = locale, replacements = replacements) /** Quick access to translate strings using this check context's [locale]. **/ public fun translate( @@ -180,7 +180,7 @@ public open class CheckContext( replacements: Array = arrayOf(), ): String = - translations.translate(key, locale, bundleName = defaultBundle, replacements = replacements) + translations.translate(key = key, bundleName = defaultBundle, locale = locale, replacements = replacements) /** Quick access to translate strings using this check context's [locale]. **/ public fun translate( @@ -189,7 +189,7 @@ public open class CheckContext( replacements: Map, ): String = - translations.translate(key, locale, bundleName = defaultBundle, replacements = replacements) + translations.translate(key = key, bundleName = defaultBundle, locale = locale, replacements = replacements) /** Quick access to translate strings using this check context's [locale]. **/ public fun translate( @@ -200,7 +200,7 @@ public open class CheckContext( bundle: String?, replacements: Map, ): String = - translations.translate(key, locale, bundleName = bundle, replacements = replacements) + translations.translate(key = key, bundleName = bundle, locale = locale, replacements = replacements) /** * If this check has failed and a message is set, throw a [DiscordRelayedException] with the translated message. diff --git a/kord-extensions/src/main/kotlin/dev/kordex/core/commands/Argument.kt b/kord-extensions/src/main/kotlin/dev/kordex/core/commands/Argument.kt index b2fdb947ac..29f3eb5835 100644 --- a/kord-extensions/src/main/kotlin/dev/kordex/core/commands/Argument.kt +++ b/kord-extensions/src/main/kotlin/dev/kordex/core/commands/Argument.kt @@ -29,4 +29,8 @@ public data class Argument( } internal fun Argument<*>.getDefaultTranslatedDisplayName(provider: TranslationsProvider, command: Command): String = - provider.translate(displayName, provider.defaultLocale, command.resolvedBundle ?: converter.bundle) + provider.translate( + key = displayName, + bundleName = command.resolvedBundle ?: converter.bundle, + locale = provider.defaultLocale + ) diff --git a/kord-extensions/src/main/kotlin/dev/kordex/core/commands/CommandContext.kt b/kord-extensions/src/main/kotlin/dev/kordex/core/commands/CommandContext.kt index a73fe21fd7..8734214349 100644 --- a/kord-extensions/src/main/kotlin/dev/kordex/core/commands/CommandContext.kt +++ b/kord-extensions/src/main/kotlin/dev/kordex/core/commands/CommandContext.kt @@ -101,7 +101,12 @@ public abstract class CommandContext( ): String { val locale = getLocale() - return translationsProvider.translate(key, locale, bundleName, replacements) + return translationsProvider.translate( + key = key, + bundleName = bundleName, + locale = locale, + replacements = replacements + ) } public override suspend fun translate( @@ -111,6 +116,11 @@ public abstract class CommandContext( ): String { val locale = getLocale() - return translationsProvider.translate(key, locale, bundleName, replacements) + return translationsProvider.translate( + key = key, + bundleName = bundleName, + locale = locale, + replacements = replacements + ) } } diff --git a/kord-extensions/src/main/kotlin/dev/kordex/core/commands/application/ApplicationCommand.kt b/kord-extensions/src/main/kotlin/dev/kordex/core/commands/application/ApplicationCommand.kt index 1a5f74f32a..32bfe3fab4 100644 --- a/kord-extensions/src/main/kotlin/dev/kordex/core/commands/application/ApplicationCommand.kt +++ b/kord-extensions/src/main/kotlin/dev/kordex/core/commands/application/ApplicationCommand.kt @@ -121,9 +121,9 @@ public abstract class ApplicationCommand( lowerCase: Boolean = false, ): Localized { var default = translationsProvider.translate( - key, - this.resolvedBundle, - translationsProvider.defaultLocale + key = key, + bundleName = this.resolvedBundle, + locale = translationsProvider.defaultLocale ) if (lowerCase) { @@ -133,9 +133,9 @@ public abstract class ApplicationCommand( val translations = bot.settings.i18nBuilder.applicationCommandLocales .associateWith { locale -> val result = translationsProvider.translate( - key, - this.resolvedBundle, - locale.asJavaLocale() + key = key, + bundleName = this.resolvedBundle, + locale = locale.asJavaLocale() ) if (lowerCase) { diff --git a/kord-extensions/src/main/kotlin/dev/kordex/core/commands/application/slash/SlashGroup.kt b/kord-extensions/src/main/kotlin/dev/kordex/core/commands/application/slash/SlashGroup.kt index 5092e1492a..7382382be7 100644 --- a/kord-extensions/src/main/kotlin/dev/kordex/core/commands/application/slash/SlashGroup.kt +++ b/kord-extensions/src/main/kotlin/dev/kordex/core/commands/application/slash/SlashGroup.kt @@ -67,9 +67,9 @@ public class SlashGroup( if (!descriptionTranslationCache.containsKey(locale)) { descriptionTranslationCache[locale] = translationsProvider.translate( - this.description, - this.parent.resolvedBundle, - locale + key = this.description, + bundleName = this.parent.resolvedBundle, + locale = locale ).lowercase() } diff --git a/kord-extensions/src/main/kotlin/dev/kordex/core/commands/chat/ChatCommand.kt b/kord-extensions/src/main/kotlin/dev/kordex/core/commands/chat/ChatCommand.kt index e2e573d44f..54d5727296 100644 --- a/kord-extensions/src/main/kotlin/dev/kordex/core/commands/chat/ChatCommand.kt +++ b/kord-extensions/src/main/kotlin/dev/kordex/core/commands/chat/ChatCommand.kt @@ -137,9 +137,9 @@ public open class ChatCommand( if (!signatureCache.containsKey(locale)) { if (signature != null) { signatureCache[locale] = translationsProvider.translate( - signature!!, - resolvedBundle, - locale + key = signature!!, + bundleName = resolvedBundle, + locale = locale ) } else { signatureCache[locale] = registry.parser.signature(arguments!!, locale) @@ -153,9 +153,9 @@ public open class ChatCommand( public open fun getTranslatedName(locale: Locale): String { if (!nameTranslationCache.containsKey(locale)) { nameTranslationCache[locale] = translationsProvider.translate( - this.name, - this.resolvedBundle, - locale + key = this.name, + bundleName = this.resolvedBundle, + locale = locale ).lowercase() } @@ -166,7 +166,7 @@ public open class ChatCommand( public open fun getTranslatedAliases(locale: Locale): Set { if (!aliasTranslationCache.containsKey(locale)) { val translations = if (aliasKey != null) { - translationsProvider.translate(aliasKey!!, resolvedBundle, locale) + translationsProvider.translate(key = aliasKey!!, bundleName = resolvedBundle, locale = locale) .lowercase() .split(",") .map { it.trim() } @@ -174,7 +174,7 @@ public open class ChatCommand( .toSortedSet() } else { this.aliases.map { - translationsProvider.translate(it, resolvedBundle, locale).lowercase() + translationsProvider.translate(key = it, bundleName = resolvedBundle, locale = locale).lowercase() }.toSortedSet() } 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 4406d2562e..e1298ac4ea 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 @@ -875,9 +875,9 @@ public open class ChatCommandParser : KordExKoinComponent { append( translationsProvider.translate( - it.converter.signatureTypeString, - it.converter.bundle, - locale + key = it.converter.signatureTypeString, + bundleName = it.converter.bundle, + locale = locale ) ) diff --git a/kord-extensions/src/main/kotlin/dev/kordex/core/commands/chat/ChatSubCommand.kt b/kord-extensions/src/main/kotlin/dev/kordex/core/commands/chat/ChatSubCommand.kt index 7d12690a5d..b6e98bd015 100644 --- a/kord-extensions/src/main/kotlin/dev/kordex/core/commands/chat/ChatSubCommand.kt +++ b/kord-extensions/src/main/kotlin/dev/kordex/core/commands/chat/ChatSubCommand.kt @@ -45,9 +45,9 @@ public open class ChatSubCommand( override fun getTranslatedName(locale: Locale): String { if (!nameTranslationCache.containsKey(locale)) { nameTranslationCache[locale] = translationsProvider.translate( - this.name, - this.resolvedBundle, - locale + key = this.name, + bundleName = this.resolvedBundle, + locale = locale ).lowercase() } diff --git a/kord-extensions/src/main/kotlin/dev/kordex/core/commands/converters/impl/TagConverter.kt b/kord-extensions/src/main/kotlin/dev/kordex/core/commands/converters/impl/TagConverter.kt index e26ccd0c72..5eb0e583a3 100644 --- a/kord-extensions/src/main/kotlin/dev/kordex/core/commands/converters/impl/TagConverter.kt +++ b/kord-extensions/src/main/kotlin/dev/kordex/core/commands/converters/impl/TagConverter.kt @@ -159,14 +159,14 @@ public class TagConverter( if (channel == null) { throw DiscordRelayedException( translationsProvider.translate( - if (getter == null) { + key = if (getter == null) { "converters.tag.error.wrongChannelType" } else { "converters.tag.error.wrongChannelTypeWithGetter" }, - event.getLocale(), - DEFAULT_KORDEX_BUNDLE + bundleName = DEFAULT_KORDEX_BUNDLE, + locale = event.getLocale(), ) ) } diff --git a/kord-extensions/src/main/kotlin/dev/kordex/core/components/ComponentContext.kt b/kord-extensions/src/main/kotlin/dev/kordex/core/components/ComponentContext.kt index faad96dcc7..360d88b456 100644 --- a/kord-extensions/src/main/kotlin/dev/kordex/core/components/ComponentContext.kt +++ b/kord-extensions/src/main/kotlin/dev/kordex/core/components/ComponentContext.kt @@ -147,7 +147,12 @@ public abstract class ComponentContext( ): String { val locale = getLocale() - return translationsProvider.translate(key, locale, bundleName, replacements) + return translationsProvider.translate( + key = key, + bundleName = bundleName, + locale = locale, + replacements = replacements + ) } /** @@ -161,7 +166,12 @@ public abstract class ComponentContext( ): String { val locale = getLocale() - return translationsProvider.translate(key, locale, bundleName, replacements) + return translationsProvider.translate( + key = key, + bundleName = bundleName, + locale = locale, + replacements = replacements + ) } /** diff --git a/kord-extensions/src/main/kotlin/dev/kordex/core/components/forms/ModalForm.kt b/kord-extensions/src/main/kotlin/dev/kordex/core/components/forms/ModalForm.kt index 11e513bacb..8576876b96 100644 --- a/kord-extensions/src/main/kotlin/dev/kordex/core/components/forms/ModalForm.kt +++ b/kord-extensions/src/main/kotlin/dev/kordex/core/components/forms/ModalForm.kt @@ -145,7 +145,7 @@ public abstract class ModalForm : Form(), KordExKoinComponent { /** Return a translated modal title using the given locale, and the given bundle if the modal doesn't have one. **/ public fun translateTitle(locale: Locale, otherBundle: String?): String = - translations.translate(title, locale, bundle ?: otherBundle) + translations.translate(key = title, bundleName = bundle ?: otherBundle, locale = locale) /** * Convenience function to send this modal to the given [interaction] and await its completion, running the provided diff --git a/kord-extensions/src/main/kotlin/dev/kordex/core/components/forms/widgets/TextInputWidget.kt b/kord-extensions/src/main/kotlin/dev/kordex/core/components/forms/widgets/TextInputWidget.kt index 45fbbe39dc..686c46c325 100644 --- a/kord-extensions/src/main/kotlin/dev/kordex/core/components/forms/widgets/TextInputWidget.kt +++ b/kord-extensions/src/main/kotlin/dev/kordex/core/components/forms/widgets/TextInputWidget.kt @@ -109,7 +109,7 @@ public abstract class TextInputWidget> : Widget( } override suspend fun apply(builder: ActionRowBuilder, locale: Locale, bundle: String?) { - val translatedLabel = translations.translate(label, locale, bundle) + val translatedLabel = translations.translate(key = label, bundleName = bundle, locale = locale) if (translatedLabel.length > LABEL_LENGTH) { error( @@ -123,12 +123,12 @@ public abstract class TextInputWidget> : Widget( this.required = this@TextInputWidget.required this.placeholder = this@TextInputWidget.placeholder?.let { - translations.translate(it, locale, bundle) + translations.translate(key = it, bundleName = bundle, locale = locale) } this.value = this@TextInputWidget.initialValue?.let { if (translateInitialValue) { - translations.translate(it, locale, bundle) + translations.translate(key = it, bundleName = bundle, locale = locale) } else { it } diff --git a/kord-extensions/src/main/kotlin/dev/kordex/core/events/EventContext.kt b/kord-extensions/src/main/kotlin/dev/kordex/core/events/EventContext.kt index b333168ca6..911de3c03a 100644 --- a/kord-extensions/src/main/kotlin/dev/kordex/core/events/EventContext.kt +++ b/kord-extensions/src/main/kotlin/dev/kordex/core/events/EventContext.kt @@ -56,7 +56,12 @@ public open class EventContext( ): String { val locale: Locale = getLocale() - return translationsProvider.translate(key, locale, bundleName, replacements) + return translationsProvider.translate( + key = key, + bundleName = bundleName, + locale = locale, + replacements = replacements + ) } /** @@ -70,7 +75,12 @@ public open class EventContext( ): String { val locale: Locale = getLocale() - return translationsProvider.translate(key, locale, bundleName, replacements) + return translationsProvider.translate( + key = key, + bundleName = bundleName, + locale = locale, + replacements = replacements + ) } override suspend fun getLocale(): Locale { diff --git a/kord-extensions/src/main/kotlin/dev/kordex/core/events/EventHandler.kt b/kord-extensions/src/main/kotlin/dev/kordex/core/events/EventHandler.kt index 38431483a5..a3b8f7e8b9 100644 --- a/kord-extensions/src/main/kotlin/dev/kordex/core/events/EventHandler.kt +++ b/kord-extensions/src/main/kotlin/dev/kordex/core/events/EventHandler.kt @@ -251,7 +251,12 @@ public open class EventHandler( ): String { val locale = getLocale() - return translationsProvider.translate(key, locale, bundleName, replacements) + return translationsProvider.translate( + key = key, + bundleName = bundleName, + locale = locale, + replacements = replacements + ) } /** @@ -265,7 +270,12 @@ public open class EventHandler( ): String { val locale = getLocale() - return translationsProvider.translate(key, locale, bundleName, replacements) + return translationsProvider.translate( + key = key, + bundleName = bundleName, + locale = locale, + replacements = replacements + ) } /** diff --git a/kord-extensions/src/main/kotlin/dev/kordex/core/extensions/impl/HelpExtension.kt b/kord-extensions/src/main/kotlin/dev/kordex/core/extensions/impl/HelpExtension.kt index e03df2db69..199e8b368f 100644 --- a/kord-extensions/src/main/kotlin/dev/kordex/core/extensions/impl/HelpExtension.kt +++ b/kord-extensions/src/main/kotlin/dev/kordex/core/extensions/impl/HelpExtension.kt @@ -281,10 +281,20 @@ public class HelpExtension : HelpProvider, Extension() { val description = buildString { if (longDescription) { - append(translationsProvider.translate(command.description, command.extension.bundle, locale)) + append( + translationsProvider.translate( + key = command.description, + bundleName = command.extension.bundle, + locale = locale + ) + ) } else { append( - translationsProvider.translate(command.description, command.extension.bundle, locale) + translationsProvider.translate( + key = command.description, + bundleName = command.extension.bundle, + locale = locale + ) .trim() .takeWhile { it != '\n' } ) @@ -383,9 +393,9 @@ public class HelpExtension : HelpProvider, Extension() { append( translationsProvider.translate( - it.converter.signatureTypeString, - it.converter.bundle, - locale + key = it.converter.signatureTypeString, + bundleName = it.converter.bundle, + locale = locale ) ) @@ -393,7 +403,13 @@ public class HelpExtension : HelpProvider, Extension() { } append("`: ") - append(translationsProvider.translate(it.description, command.extension.bundle, locale)) + append( + translationsProvider.translate( + key = it.description, + bundleName = command.extension.bundle, + locale = locale + ) + ) } } ) diff --git a/kord-extensions/src/main/kotlin/dev/kordex/core/i18n/ResourceBundleTranslations.kt b/kord-extensions/src/main/kotlin/dev/kordex/core/i18n/ResourceBundleTranslations.kt index cc9e3ec840..8b3746a168 100644 --- a/kord-extensions/src/main/kotlin/dev/kordex/core/i18n/ResourceBundleTranslations.kt +++ b/kord-extensions/src/main/kotlin/dev/kordex/core/i18n/ResourceBundleTranslations.kt @@ -32,21 +32,18 @@ import java.util.* public open class ResourceBundleTranslations( defaultLocaleBuilder: () -> Locale, ) : TranslationsProvider(defaultLocaleBuilder) { - private val logger: KLogger = KotlinLogging.logger( - "dev.kordex.core.i18n.ResourceBundleTranslations" - ) - + private val logger: KLogger = KotlinLogging.logger { } private val bundles: MutableMap, ResourceBundle> = mutableMapOf() private val overrideBundles: MutableMap, ResourceBundle> = mutableMapOf() - public override fun hasKey(key: String, locale: Locale, bundleName: String?): Boolean { + public override fun hasKey(key: String, bundleName: String?, locale: Locale): Boolean { return try { - val (bundle, _) = getBundles(locale, bundleName) + val (bundle, _) = getBundles(bundleName, locale) // Overrides aren't for adding keys, so we don't check them bundle.keys.toList().contains(key) } catch (e: MissingResourceException) { - logger.trace { "Failed to get bundle $bundleName for locale $locale" } + logger.trace(e) { "Failed to get bundle $bundleName for locale $locale" } false } @@ -67,7 +64,10 @@ public open class ResourceBundleTranslations( * Retrieves a pair of the [ResourceBundle] and the override resource bundle for [bundleName] in locale. */ @Throws(MissingResourceException::class) - protected open fun getBundles(locale: Locale, bundleName: String?): Pair { + protected open fun getBundles(bundleName: String?, nullableLocale: Locale?): Pair { + val locale = nullableLocale + ?: defaultLocale + val bundle = buildString { append("translations." + (bundleName ?: KORDEX_KEY)) @@ -108,7 +108,7 @@ public open class ResourceBundleTranslations( overrideBundles[bundleKey] = getResourceBundle(overrideBundle, locale, Control) } catch (e: MissingResourceException) { - logger.trace { "No override bundle found." } + logger.trace(e) { "No override bundle found." } } } @@ -116,8 +116,8 @@ public open class ResourceBundleTranslations( } @Throws(MissingResourceException::class) - public override fun get(key: String, locale: Locale, bundleName: String?): String { - val (bundle, overrideBundle) = getBundles(locale, bundleName) + public override fun get(key: String, bundleName: String?, locale: Locale?): String { + val (bundle, overrideBundle) = getBundles(bundleName, locale) val result = overrideBundle?.getStringOrNull(key) ?: bundle.getString(key) logger.trace { "Result: $key -> $result" } @@ -130,10 +130,10 @@ public open class ResourceBundleTranslations( * * The string's parameters are not replaced. */ - protected fun getTranslatedString(key: String, locale: Locale, bundleName: String?): String { + protected fun getTranslatedString(key: String, locale: Locale?, bundleName: String?): String { var string = try { - get(key, locale, bundleName) - } catch (e: MissingResourceException) { + get(key, bundleName, locale) + } catch (_: MissingResourceException) { key } @@ -142,12 +142,12 @@ public open class ResourceBundleTranslations( // Fall through to the default bundle if the key isn't found logger.trace { "'$key' not found in bundle '$bundleName' - falling through to '$KORDEX_KEY'" } - string = get(key, locale, KORDEX_KEY) + string = get(key, KORDEX_KEY, locale) } string } catch (e: MissingResourceException) { - logger.trace { + logger.trace(e) { if (bundleName == null) { "Unable to find translation for key '$key' in bundle '$KORDEX_KEY'" } else { @@ -159,7 +159,7 @@ public open class ResourceBundleTranslations( } } - override fun translate(key: String, locale: Locale, bundleName: String?, replacements: Array): String { + override fun translate(key: String, bundleName: String?, locale: Locale?, replacements: Array): String { val string = getTranslatedString(key, locale, bundleName) val formatter = MessageFormat(string, locale) @@ -167,7 +167,7 @@ public open class ResourceBundleTranslations( return formatter.format(replacements) } - override fun translate(key: String, locale: Locale, bundleName: String?, replacements: Map): String { + override fun translate(key: String, bundleName: String?, locale: Locale?, replacements: Map): String { val string = getTranslatedString(key, locale, bundleName) val formatter = MessageFormat(string, locale) @@ -178,7 +178,7 @@ public open class ResourceBundleTranslations( private fun ResourceBundle.getStringOrNull(key: String): String? { return try { getString(key) - } catch (e: MissingResourceException) { + } catch (_: MissingResourceException) { null } } diff --git a/kord-extensions/src/main/kotlin/dev/kordex/core/i18n/TranslationsProvider.kt b/kord-extensions/src/main/kotlin/dev/kordex/core/i18n/TranslationsProvider.kt index b53b1ccb2d..5e7a3188ff 100644 --- a/kord-extensions/src/main/kotlin/dev/kordex/core/i18n/TranslationsProvider.kt +++ b/kord-extensions/src/main/kotlin/dev/kordex/core/i18n/TranslationsProvider.kt @@ -26,135 +26,38 @@ public abstract class TranslationsProvider( public open val defaultLocale: Locale by lazy { defaultLocaleBuilder() } /** Check whether a translation key exists in the given bundle and locale. **/ - public abstract fun hasKey(key: String, locale: Locale, bundleName: String?): Boolean - - /** Get a translation by key from the given bundle name (`kordex.strings` by default). **/ - public open fun get(key: String, bundleName: String? = null): String = - get(key, defaultLocale, bundleName) + public abstract fun hasKey(key: String, bundleName: String?, locale: Locale): Boolean /** Get a translation by key from the given locale and bundle name (`kordex.strings` by default). **/ - public abstract fun get(key: String, locale: Locale, bundleName: String? = null): String - - /** Get a translation by key from the given language code and bundle name (`kordex.strings` by default). **/ - public open fun get(key: String, language: String, bundleName: String? = null): String = - get(key, Locale(language), bundleName) - - /** - * Get a translation by key from the given language and country codes, and bundle name (`kordex.strings` by - * default). - */ - public open fun get(key: String, language: String, country: String, bundleName: String? = null): String = - get(key, Locale(language, country), bundleName) - - /** Get a formatted translation using the provided arguments. **/ - public open fun translate( - key: String, - bundleName: String? = null, - replacements: Array = arrayOf(), - ): String = translate(key, defaultLocale, bundleName, replacements) - - /** Get a formatted translation using the provided arguments. **/ - public open fun translate( - key: String, - bundleName: String? = null, - locale: Locale, - replacements: Array = arrayOf(), - ): String = translate(key, locale, bundleName, replacements) + public abstract fun get(key: String, bundleName: String? = null, locale: Locale? = null): String /** Get a formatted translation using the provided arguments. **/ public abstract fun translate( key: String, - locale: Locale, bundleName: String? = null, + locale: Locale? = null, replacements: Array = arrayOf(), ): String - /** Get a formatted translation using the provided arguments. **/ - public open fun translate( - key: String, - language: String, - bundleName: String? = null, - replacements: Array = arrayOf(), - ): String = translate(key, Locale(language), bundleName, replacements) - - /** Get a formatted translation using the provided arguments. **/ - public open fun translate( - key: String, - language: String, - country: String, - bundleName: String? = null, - replacements: Array = arrayOf(), - ): String = translate(key, Locale(language, country), bundleName, replacements) - - /** Get a formatted translation using the provided arguments. **/ - public open fun translate( - key: String, - bundleName: String? = null, - replacements: List, - ): String = translate(key, bundleName, replacements.toTypedArray()) - - /** Get a formatted translation using the provided arguments. **/ - public fun translate( - key: String, - locale: Locale, - bundleName: String? = null, - replacements: List, - ): String = translate(key, locale, bundleName, replacements.toTypedArray()) - - /** Get a formatted translation using the provided arguments. **/ - public open fun translate( - key: String, - language: String, - bundleName: String? = null, - replacements: List, - ): String = translate(key, language, bundleName, replacements.toTypedArray()) - - /** Get a formatted translation using the provided arguments. **/ - public open fun translate( - key: String, - language: String, - country: String, - bundleName: String? = null, - replacements: List, - ): String = translate(key, language, country, bundleName, replacements.toTypedArray()) - - /** Get a formatted translation using the provided arguments. **/ - public open fun translate( - key: String, - bundleName: String? = null, - replacements: Map, - ): String = translate(key, defaultLocale, bundleName, replacements) - - /** Get a formatted translation using the provided arguments. **/ - public open fun translate( - key: String, - bundleName: String? = null, - locale: Locale, - replacements: Map, - ): String = translate(key, locale, bundleName, replacements) - /** Get a formatted translation using the provided arguments. **/ public abstract fun translate( key: String, - locale: Locale, bundleName: String? = null, + locale: Locale? = null, replacements: Map, ): String /** Get a formatted translation using the provided arguments. **/ public open fun translate( key: String, - language: String, - bundleName: String? = null, - replacements: Map, - ): String = translate(key, Locale(language), bundleName, replacements) + locale: Locale? = null, + replacements: Array = arrayOf(), + ): String = translate(key = key, bundleName = null, locale = locale, replacements = replacements) /** Get a formatted translation using the provided arguments. **/ public open fun translate( key: String, - language: String, - country: String, - bundleName: String? = null, + locale: Locale? = null, replacements: Map, - ): String = translate(key, Locale(language, country), bundleName, replacements) + ): String = translate(key = key, bundleName = null, locale = locale, replacements = replacements) } diff --git a/kord-extensions/src/main/kotlin/dev/kordex/core/pagination/BasePaginator.kt b/kord-extensions/src/main/kotlin/dev/kordex/core/pagination/BasePaginator.kt index c9ade61137..20297226f8 100644 --- a/kord-extensions/src/main/kotlin/dev/kordex/core/pagination/BasePaginator.kt +++ b/kord-extensions/src/main/kotlin/dev/kordex/core/pagination/BasePaginator.kt @@ -246,5 +246,5 @@ public abstract class BasePaginator( /** Quick access to translations, using the paginator's locale and bundle. **/ public fun translate(key: String, replacements: Array = arrayOf()): String = - translations.translate(key, localeObj, bundle, replacements = replacements) + translations.translate(key = key, bundleName = bundle, locale = localeObj, replacements = replacements) } diff --git a/kord-extensions/src/main/kotlin/dev/kordex/core/pagination/pages/Page.kt b/kord-extensions/src/main/kotlin/dev/kordex/core/pagination/pages/Page.kt index ec40a3e6c1..6f4796fdbb 100644 --- a/kord-extensions/src/main/kotlin/dev/kordex/core/pagination/pages/Page.kt +++ b/kord-extensions/src/main/kotlin/dev/kordex/core/pagination/pages/Page.kt @@ -98,7 +98,9 @@ public open class Page( ) } else { val groupName = translationsProvider.translate( - group, locale, bundle + key = group, + bundleName = bundle, + locale = locale ).capitalizeWords(locale) append("$groupName (${groupIndex + 1}/$groups)") 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 7643287f4f..41b2770dad 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 @@ -50,7 +50,7 @@ public class UnionConverter( private val translations: TranslationsProvider by inject() override val signatureTypeString: String = typeName ?: converters.joinToString(" | ") { - translations.translate(it.signatureTypeString, it.bundle) + translations.translate(key = it.signatureTypeString, bundleName = it.bundle) } /** @suppress Internal validation function. **/ diff --git a/modules/integrations/pluralkit/src/main/kotlin/dev/kordex/modules/pluralkit/PKExtension.kt b/modules/integrations/pluralkit/src/main/kotlin/dev/kordex/modules/pluralkit/PKExtension.kt index dc413108cd..27d88fe456 100644 --- a/modules/integrations/pluralkit/src/main/kotlin/dev/kordex/modules/pluralkit/PKExtension.kt +++ b/modules/integrations/pluralkit/src/main/kotlin/dev/kordex/modules/pluralkit/PKExtension.kt @@ -306,7 +306,7 @@ class PKExtension(val config: PKConfigBuilder) : Extension() { translate("arguments.reset"), translationsProvider.translate( - "arguments.reset", + key = "arguments.reset", bundleName = this@ephemeralSubCommand.bundle ) ) @@ -448,9 +448,9 @@ class PKExtension(val config: PKConfigBuilder) : Extension() { private fun Boolean.emote() = if (this) { - dev.kordex.modules.pluralkit.POSITIVE_EMOTE + POSITIVE_EMOTE } else { - dev.kordex.modules.pluralkit.NEGATIVE_EMOTE + NEGATIVE_EMOTE } private fun GuildBehavior.configUnit() =