Skip to content

Commit

Permalink
Support Spanish (Latin America) (#906)
Browse files Browse the repository at this point in the history
  • Loading branch information
gdude2002 authored and lukellmann committed Jan 9, 2024
1 parent 8bec800 commit 406e36e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions common/api/common.api
Original file line number Diff line number Diff line change
Expand Up @@ -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;
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 @@ -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.
*/
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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.
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

0 comments on commit 406e36e

Please sign in to comment.