Skip to content

Commit 393b9c7

Browse files
committed
refactor: add Android adapters to java.util.Locale
1 parent f538b99 commit 393b9c7

5 files changed

Lines changed: 39 additions & 1 deletion

File tree

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ fun calculateVersion(baseVersion: String): String {
3030
}
3131

3232
group = "net.igsoft.polyglot"
33-
version = calculateVersion("0.3.0")
33+
version = calculateVersion("0.3.1")
3434

3535
println("Version: $version")
3636

polyglot-core/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ kotlin {
1111
namespace = "net.igsoft.polyglot.core"
1212
compileSdk = 37
1313
minSdk = 23
14+
withHostTest {}
1415
compilerOptions {
1516
jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17)
1617
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package net.igsoft.polyglot.core
2+
3+
import java.util.Locale
4+
import kotlin.test.Test
5+
import kotlin.test.assertEquals
6+
7+
class MsgLocaleAndroidTest {
8+
9+
@Test
10+
fun `Given French locale when converting to message locale then preserve language tag`() {
11+
assertEquals(MsgLocale.of("fr-FR"), Locale.forLanguageTag("fr-FR").toMsgLocale())
12+
}
13+
14+
@Test
15+
fun `Given French message locale when converting to Java locale then preserve language tag`() {
16+
assertEquals(Locale.forLanguageTag("fr-FR"), MsgLocale.of("fr-FR").toJavaLocale())
17+
}
18+
19+
@Test
20+
fun `Given German locale when creating message locale then preserve language tag`() {
21+
assertEquals(MsgLocale.of("de"), MsgLocale.of(Locale.GERMAN))
22+
}
23+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package net.igsoft.polyglot.core
2+
3+
import java.util.Locale
4+
5+
fun MsgLocale.Companion.of(locale: Locale): MsgLocale = MsgLocale.of(locale.toLanguageTag())
6+
7+
fun Locale.toMsgLocale(): MsgLocale = MsgLocale.of(this)
8+
9+
fun MsgLocale.toJavaLocale(): Locale = Locale.forLanguageTag(languageTag)

polyglot-core/src/commonMain/kotlin/net/igsoft/polyglot/core/MsgLocales.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,9 @@ object MsgLocales {
1212

1313
val PL_PL: MsgLocale
1414
get() = MsgLocale.of("pl-PL")
15+
16+
val DE get() = MsgLocale.of("de")
17+
val ES get() = MsgLocale.of("es")
18+
val FR get() = MsgLocale.of("fr")
19+
val IT get() = MsgLocale.of("it")
1520
}

0 commit comments

Comments
 (0)