Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Spanish (Latin America) #906

Merged
merged 1 commit into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions common/api/common.api
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,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;
Expand Down
10 changes: 8 additions & 2 deletions common/src/commonMain/kotlin/Locale.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,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.
*/
Expand Down Expand Up @@ -184,6 +189,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,
Expand Down Expand Up @@ -211,8 +217,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.
Expand Down
2 changes: 1 addition & 1 deletion common/src/commonTest/kotlin/LocaleTest.kt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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,
Expand Down