Skip to content

Commit 47cae33

Browse files
committed
refactor(adapter): move Locale adapters to dedicated module
Extract shared JVM and Android Locale adapters with their tests from polyglot-core.
1 parent 393b9c7 commit 47cae33

8 files changed

Lines changed: 141 additions & 83 deletions

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.1")
33+
version = calculateVersion("0.3.2")
3434

3535
println("Version: $version")
3636

polyglot-adapter/build.gradle.kts

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
plugins {
2+
kotlin("multiplatform")
3+
id("com.android.kotlin.multiplatform.library")
4+
id("com.adarshr.test-logger")
5+
id("com.vanniktech.maven.publish")
6+
}
7+
8+
kotlin {
9+
applyDefaultHierarchyTemplate()
10+
11+
jvm()
12+
android {
13+
namespace = "net.igsoft.polyglot.adapter"
14+
compileSdk = 37
15+
minSdk = 23
16+
withHostTest {}
17+
compilerOptions {
18+
jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17)
19+
}
20+
}
21+
jvmToolchain(17)
22+
23+
sourceSets {
24+
val jvmAndroidMain = create("jvmAndroidMain") {
25+
dependsOn(commonMain.get())
26+
}
27+
jvmMain.get().dependsOn(jvmAndroidMain)
28+
androidMain.get().dependsOn(jvmAndroidMain)
29+
30+
val jvmAndroidTest = create("jvmAndroidTest") {
31+
dependsOn(commonTest.get())
32+
}
33+
jvmTest.get().dependsOn(jvmAndroidTest)
34+
getByName("androidHostTest").dependsOn(jvmAndroidTest)
35+
36+
commonMain.dependencies {
37+
api(project(":polyglot-core"))
38+
}
39+
40+
commonTest.dependencies {
41+
implementation(kotlin("test"))
42+
}
43+
44+
jvmTest.dependencies {
45+
implementation(kotlin("test-junit5"))
46+
runtimeOnly("org.junit.platform:junit-platform-launcher")
47+
}
48+
}
49+
}
50+
51+
testlogger {
52+
showStandardStreams = true
53+
showFullStackTraces = false
54+
}
55+
56+
val licensesSpec = Action<MavenPomLicenseSpec> {
57+
license {
58+
name.set("MIT License")
59+
url.set("https://opensource.org/licenses/MIT")
60+
}
61+
}
62+
63+
val developersSpec = Action<MavenPomDeveloperSpec> {
64+
developer {
65+
id.set("aartiPl")
66+
name.set("Marcin Kuszczak")
67+
email.set("aarti@interia.pl")
68+
}
69+
}
70+
71+
val scmSpec = Action<MavenPomScm> {
72+
connection.set("scm:git:git://https://github.com/aartiPl/polyglot.git")
73+
developerConnection.set("scm:git:ssh:https://github.com/aartiPl/polyglot.git")
74+
url.set("https://github.com/aartiPl/polyglot/tree/main")
75+
}
76+
77+
mavenPublishing {
78+
coordinates(group.toString(), project.name, version.toString())
79+
publishToMavenCentral()
80+
signAllPublications()
81+
82+
pom {
83+
name.set(project.name)
84+
description.set("JVM and Android adapters for Polyglot")
85+
url.set("https://github.com/aartiPl/polyglot")
86+
87+
licenses(licensesSpec)
88+
developers(developersSpec)
89+
scm(scmSpec)
90+
}
91+
}

polyglot-core/src/androidMain/kotlin/net/igsoft/polyglot/core/MsgLocaleAndroid.kt renamed to polyglot-adapter/src/jvmAndroidMain/kotlin/net/igsoft/polyglot/adapter/MsgLocaleJava.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
package net.igsoft.polyglot.core
1+
package net.igsoft.polyglot.adapter
22

33
import java.util.Locale
4+
import net.igsoft.polyglot.core.MsgLocale
45

56
fun MsgLocale.Companion.of(locale: Locale): MsgLocale = MsgLocale.of(locale.toLanguageTag())
67

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package net.igsoft.polyglot.adapter
2+
3+
import java.util.Locale
4+
import kotlin.test.Test
5+
import kotlin.test.assertEquals
6+
import net.igsoft.polyglot.core.MsgLocale
7+
import net.igsoft.polyglot.core.MsgLocales
8+
9+
class MsgLocaleJavaTest {
10+
11+
@Test
12+
fun `Given French locale when converting to message locale then preserve language tag`() {
13+
assertEquals(MsgLocale.of("fr-FR"), Locale.forLanguageTag("fr-FR").toMsgLocale())
14+
}
15+
16+
@Test
17+
fun `Given French message locale when converting to Java locale then preserve language tag`() {
18+
assertEquals(Locale.forLanguageTag("fr-FR"), MsgLocale.of("fr-FR").toJavaLocale())
19+
}
20+
21+
@Test
22+
fun `Given German locale when creating message locale then preserve language tag`() {
23+
assertEquals(MsgLocale.of("de"), MsgLocale.of(Locale.GERMAN))
24+
}
25+
26+
@Test
27+
fun `Given java locale when converting to message locale then normalize language tag`() {
28+
val javaLocale = Locale.forLanguageTag("pl-PL-u-ca-gregory")
29+
30+
assertEquals("pl-PL", javaLocale.toMsgLocale().languageTag)
31+
}
32+
33+
@Test
34+
@Suppress("DEPRECATION")
35+
fun `Given empty java locale when converting to message locale then return undetermined tag`() {
36+
val javaLocale = Locale("", "")
37+
38+
assertEquals("und", MsgLocale.of(javaLocale).languageTag)
39+
}
40+
41+
@Test
42+
fun `Given message locale when converting to java locale then preserve language tag`() {
43+
assertEquals("en-US", MsgLocales.EN_US.toJavaLocale().toLanguageTag())
44+
}
45+
}

polyglot-core/src/androidHostTest/kotlin/net/igsoft/polyglot/core/MsgLocaleAndroidTest.kt

Lines changed: 0 additions & 23 deletions
This file was deleted.

polyglot-core/src/jvmMain/kotlin/net/igsoft/polyglot/core/MsgLocaleJvm.kt

Lines changed: 0 additions & 9 deletions
This file was deleted.

polyglot-core/src/jvmTest/kotlin/net/igsoft/polyglot/core/MsgLocaleJvmTest.kt

Lines changed: 0 additions & 48 deletions
This file was deleted.

settings.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ dependencyResolutionManagement {
1818
rootProject.name = "polyglot"
1919

2020
include(":polyglot-core")
21-
include(":polyglot-compose")
21+
include(":polyglot-adapter")
22+
include(":polyglot-compose")

0 commit comments

Comments
 (0)