diff --git a/common/api/common.api b/common/api/common.api index 67937468a2c..d924b2a5d38 100644 --- a/common/api/common.api +++ b/common/api/common.api @@ -142,6 +142,7 @@ public final class dev/kord/common/Locale$Companion { public final fun getPORTUGUESE_BRAZIL ()Ldev/kord/common/Locale; public final fun getROMANIAN ()Ldev/kord/common/Locale; public final fun getRUSSIAN ()Ldev/kord/common/Locale; + public final fun getSPANISH_LATIN_AMERICA ()Ldev/kord/common/Locale; public final fun getSPANISH_SPAIN ()Ldev/kord/common/Locale; public final fun getSWEDISH ()Ldev/kord/common/Locale; public final fun getTHAI ()Ldev/kord/common/Locale; diff --git a/common/src/commonMain/kotlin/Locale.kt b/common/src/commonMain/kotlin/Locale.kt index 751c9380f2e..d17e5000bfa 100644 --- a/common/src/commonMain/kotlin/Locale.kt +++ b/common/src/commonMain/kotlin/Locale.kt @@ -47,6 +47,11 @@ public data class Locale(val language: String, val country: String? = null) { */ public val SPANISH_SPAIN: Locale = Locale("es", "ES") + /** + * Spanish (Latin America). + */ + public val SPANISH_LATIN_AMERICA: Locale = Locale("es", "419") + /** * French. */ @@ -183,6 +188,7 @@ public data class Locale(val language: String, val country: String? = null) { ENGLISH_GREAT_BRITAIN, ENGLISH_UNITED_STATES, SPANISH_SPAIN, + SPANISH_LATIN_AMERICA, FRENCH, CROATIAN, ITALIAN, @@ -210,8 +216,8 @@ public data class Locale(val language: String, val country: String? = null) { KOREAN, ) - // https://regex101.com/r/KCHTj8/1 - private val languageTagFormat = "([a-z]{2})(?:-([A-Z]{2}))?".toRegex() + // https://regex101.com/r/8iMEWT/1 + private val languageTagFormat = "([a-z]{2})(?:-([A-Z]{2}|\\d{3}))?".toRegex() /** * Decodes the [Locale] from a `languageCode-countryCode` or `languageCode` format. diff --git a/common/src/commonTest/kotlin/LocaleTest.kt b/common/src/commonTest/kotlin/LocaleTest.kt index 3130f7f8516..1ca6db9348e 100644 --- a/common/src/commonTest/kotlin/LocaleTest.kt +++ b/common/src/commonTest/kotlin/LocaleTest.kt @@ -1,6 +1,5 @@ package dev.kord.common -import kotlinx.serialization.decodeFromString import kotlinx.serialization.encodeToString import kotlinx.serialization.json.Json import kotlin.js.JsName @@ -17,6 +16,7 @@ class LocaleTest { "en-GB" to ENGLISH_GREAT_BRITAIN, "en-US" to ENGLISH_UNITED_STATES, "es-ES" to SPANISH_SPAIN, + "es-419" to SPANISH_LATIN_AMERICA, "fr" to FRENCH, "hr" to CROATIAN, "it" to ITALIAN,