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

Upgrade to Kotlin 2.0.0 #67

Merged
merged 3 commits into from
May 30, 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 .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.idea/
.gradle/
.kotlin/
out/
build/
log/
Expand Down
6 changes: 4 additions & 2 deletions buildSrc/src/main/kotlin/i18n4k.kmp-build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget

plugins {
kotlin("multiplatform")
}
Expand All @@ -6,8 +8,8 @@ plugins {

kotlin {
jvm {
compilations.all {
kotlinOptions.jvmTarget = "1.8"
compilerOptions {
jvmTarget = JvmTarget.JVM_1_8
}
testRuns["test"].executionTask.configure {
useJUnit()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,8 @@

package de.comahe.i18n4k.cldr.plurals

import de.comahe.i18n4k.Locale
import de.comahe.i18n4k.country
import de.comahe.i18n4k.createLocale
import de.comahe.i18n4k.language
import de.comahe.i18n4k.*
import de.comahe.i18n4k.cldr.plurals.PluralOperand.Companion.from
import de.comahe.i18n4k.rootLocale


/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package de.comahe.i18n4k.messages.formatter

import de.comahe.i18n4k.Locale
import de.comahe.i18n4k.config.I18n4kConfigDefault
import de.comahe.i18n4k.createLocale
import de.comahe.i18n4k.i18n4k
import de.comahe.i18n4k.i18n4kInitCldrPluralRules
import kotlin.test.BeforeTest
Expand All @@ -19,7 +19,7 @@ class MessagePluralsTest {
fun init() {
i18n4k = i18n4kConfig
i18n4kConfig.restoreDefaultSettings()
i18n4kConfig.locale = Locale("en")
i18n4kConfig.locale = createLocale("en")

MessagesPlurals.unregisterAllTranslations()
MessagesPlurals.registerTranslation(MessagesPlurals_en)
Expand All @@ -30,7 +30,7 @@ class MessagePluralsTest {

@Test
fun cardinalTest_en() {
i18n4kConfig.locale = Locale("en")
i18n4kConfig.locale = createLocale("en")

assertEquals("1 month", MessagesPlurals.MONTH_COUNT("1"))
assertEquals("1 month", MessagesPlurals.MONTH_COUNT(1))
Expand All @@ -50,7 +50,7 @@ class MessagePluralsTest {

@Test
fun cardinalTest_de() {
i18n4kConfig.locale = Locale("de")
i18n4kConfig.locale = createLocale("de")

assertEquals("1 Monat", MessagesPlurals.MONTH_COUNT("1"))
assertEquals("1 Monat", MessagesPlurals.MONTH_COUNT(1))
Expand All @@ -70,7 +70,7 @@ class MessagePluralsTest {

@Test
fun cardinalTest_pl() {
i18n4kConfig.locale = Locale("pl")
i18n4kConfig.locale = createLocale("pl")

assertEquals("1 miesiąc", MessagesPlurals.MONTH_COUNT("1"))
assertEquals("1 miesiąc", MessagesPlurals.MONTH_COUNT(1))
Expand All @@ -90,7 +90,7 @@ class MessagePluralsTest {

@Test
fun ordinalTest_en() {
i18n4kConfig.locale = Locale("en")
i18n4kConfig.locale = createLocale("en")

assertEquals("1st rank", MessagesPlurals.RANK_ORDINAL("1"))
assertEquals("1st rank", MessagesPlurals.RANK_ORDINAL(1))
Expand All @@ -111,7 +111,7 @@ class MessagePluralsTest {

@Test
fun ordinalTest_de() {
i18n4kConfig.locale = Locale("de")
i18n4kConfig.locale = createLocale("de")

assertEquals("1. Rang", MessagesPlurals.RANK_ORDINAL("1"))
assertEquals("1. Rang", MessagesPlurals.RANK_ORDINAL(1))
Expand All @@ -132,7 +132,7 @@ class MessagePluralsTest {

@Test
fun ordinalTest_pl() {
i18n4kConfig.locale = Locale("pl")
i18n4kConfig.locale = createLocale("pl")

assertEquals("1. rząd", MessagesPlurals.RANK_ORDINAL("1"))
assertEquals("1. rząd", MessagesPlurals.RANK_ORDINAL(1))
Expand Down
10 changes: 9 additions & 1 deletion i18n4k-core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
@file:OptIn(ExperimentalKotlinGradlePluginApi::class)

import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi

plugins {
id("i18n4k.kmp-build")
id("i18n4k.publish-build")
Expand All @@ -6,7 +10,7 @@ plugins {

kotlin {
// the sources of all the targets
@Suppress("UNUSED_VARIABLE", "UnusedPrivateMember")
@Suppress("UnusedPrivateMember")
sourceSets {

val commonMain by getting {
Expand Down Expand Up @@ -43,4 +47,8 @@ kotlin {
}
}
}

compilerOptions {
freeCompilerArgs.add("-Xexpect-actual-classes")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ fun createDefaultLocaleImpl(

return DefaultLocaleImpl(
language.trim().lowercase(),
script?.trim()?.capitalize() ?: "",
script?.trim()?.replaceFirstChar { if (it.isLowerCase()) it.titlecase() else it.toString() } ?: "",
country?.trim()?.uppercase() ?: "",
variant?.trim()?.lowercase() ?: "",
extensionsBuilder.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ val Locale.lessSpecificLocale: Locale
var result = lessSpecificLocaleCache.value[this]
if (result === null) {
result = if (variant.isEmpty())
Locale(language)
createLocale(language)
else
Locale(language, country)
createLocale(language, null, country)
}
lessSpecificLocaleCache.update { it.put(this, result) }

Expand Down Expand Up @@ -138,7 +138,7 @@ fun forLocaleTag(languageTag: String, separator: Char = '_', separator2: Char =
fun String.isAlphaNum() = all { it.isLetterOrDigit() }


var index = 0;
var index = 0

if (parts.size > index
&& parts[index].isAlpha()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package de.comahe.i18n4k.config

import de.comahe.i18n4k.Locale
import de.comahe.i18n4k.createLocale
import de.comahe.i18n4k.messages.formatter.MessageFormatter
import de.comahe.i18n4k.messages.formatter.MessageFormatterDefault
import de.comahe.i18n4k.messages.formatter.provider.DeclensionProvider
Expand All @@ -22,7 +23,7 @@ class I18n4kConfigDefault : I18n4kConfig {

/** atomic ref for [defaultLocale] */
private val defaultLocaleRef: AtomicRef<Locale> =
atomic(Locale("en"))
atomic(createLocale("en"))

/** atomic ref for [locale] */
private val localeRef: AtomicRef<Locale> =
Expand All @@ -47,7 +48,7 @@ class I18n4kConfigDefault : I18n4kConfig {

/** Restores the default settings. */
fun restoreDefaultSettings() {
defaultLocale = Locale("en")
defaultLocale = createLocale("en")
locale = systemLocale
messageFormatter = MessageFormatterDefault
treadBlankStringAsNull = true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package de.comahe.i18n4k.config

import de.comahe.i18n4k.Locale
import de.comahe.i18n4k.createLocale
import de.comahe.i18n4k.forLocaleTag
import de.comahe.i18n4k.messages.formatter.MessageFormatter
import de.comahe.i18n4k.messages.formatter.MessageFormatterDefault
Expand Down Expand Up @@ -28,7 +29,7 @@ data class I18n4kConfigImmutable(
) : I18n4kConfig {
/** constructor for getting the default settings */
constructor() : this(
defaultLocale = Locale("en"),
defaultLocale = createLocale("en"),
locale = systemLocale,
messageFormatter = MessageFormatterDefault,
treadBlankStringAsNull = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,13 @@

package de.comahe.i18n4k.messages

import de.comahe.i18n4k.Locale
import de.comahe.i18n4k.applyLocales
import de.comahe.i18n4k.i18n4k
import de.comahe.i18n4k.lessSpecificLocale
import de.comahe.i18n4k.*
import de.comahe.i18n4k.messages.formatter.MessageFormatter
import de.comahe.i18n4k.messages.formatter.MessageParameters
import de.comahe.i18n4k.messages.formatter.MessageParametersEmpty
import de.comahe.i18n4k.messages.formatter.MessageParametersList
import de.comahe.i18n4k.messages.providers.MessagesProvider
import de.comahe.i18n4k.messages.providers.MessagesProviderFactory
import de.comahe.i18n4k.removeExtensions
import de.comahe.i18n4k.rootLocale
import de.comahe.i18n4k.strings.AbstractLocalizedString
import de.comahe.i18n4k.strings.LocalizedString
import de.comahe.i18n4k.strings.LocalizedStringFactoryX
Expand Down Expand Up @@ -133,7 +128,7 @@ open class MessageBundle(
}

fun getEntryByIndex(index: Int): MessageBundleEntry? {
val list = keyObjectsByIndex.value;
val list = keyObjectsByIndex.value
if (index < 0 || index >= list.size)
return null
return list[index]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package de.comahe.i18n4k.messages.formatter.provider

import de.comahe.i18n4k.Locale
import de.comahe.i18n4k.strings.LocalizedAttributable
import de.comahe.i18n4k.strings.LocalizedString

interface DeclensionProvider {
fun getDeclensionOf(declensionCase: CharSequence, value: Any?, locale: Locale?): String?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package de.comahe.i18n4k.messages.formatter.provider

import de.comahe.i18n4k.Locale
import de.comahe.i18n4k.strings.LocalizedAttributable
import de.comahe.i18n4k.strings.LocalizedString

interface GenderProvider {
fun getGenderOf(value: Any?, locale: Locale?): String?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import de.comahe.i18n4k.messages.formatter.MessageParameters
import de.comahe.i18n4k.messages.formatter.MessageValueFormatter
import de.comahe.i18n4k.messages.formatter.parsing.StylePart
import de.comahe.i18n4k.strings.LocalizedAttributable
import de.comahe.i18n4k.strings.LocalizedString

/**
* Select a text value based on the named attribute value of the parameter.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import de.comahe.i18n4k.messages.formatter.MessageValueFormatter
import de.comahe.i18n4k.messages.formatter.parsing.StylePart
import de.comahe.i18n4k.messages.formatter.parsing.firstMessagePart
import de.comahe.i18n4k.strings.LocalizedAttributable
import de.comahe.i18n4k.strings.LocalizedString

/**
* Inserts the values of the given attribute of the parameter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ import de.comahe.i18n4k.messages.formatter.MessageParameters
import de.comahe.i18n4k.messages.formatter.MessageValueFormatter
import de.comahe.i18n4k.messages.formatter.parsing.StylePart
import de.comahe.i18n4k.messages.formatter.parsing.firstMessagePart
import de.comahe.i18n4k.messages.formatter.provider.DeclensionProvider
import de.comahe.i18n4k.messages.formatter.provider.DeclensionProviderDefault
import kotlinx.atomicfu.atomic
import kotlinx.atomicfu.update

/**
* For languages that have irregular declension, a declension-provider is needed to find the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ import de.comahe.i18n4k.messages.formatter.MessageFormatContext
import de.comahe.i18n4k.messages.formatter.MessageParameters
import de.comahe.i18n4k.messages.formatter.MessageValueFormatter
import de.comahe.i18n4k.messages.formatter.parsing.StylePart
import de.comahe.i18n4k.messages.formatter.provider.GenderProvider
import de.comahe.i18n4k.messages.formatter.provider.GenderProviderDefault
import de.comahe.i18n4k.messages.formatter.provider.GenderProviderDefault.getGenderOf
import kotlinx.atomicfu.atomic
import kotlinx.atomicfu.update

/**
* It is like a normal select-pattern (#36), but instead of using the value of the parameter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ object MessageSelectFormatter : MessageValueFormatter {
if (style is StylePartMessage)
return style.messagePart

var foundMatch = false;
var foundMatch = false
if (style is StylePartList) {
for (subStyle in style.list) {
if (subStyle is StylePartArgument && valueMatches(value, subStyle.value))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package de.comahe.i18n4k.messages.providers

import de.comahe.i18n4k.Locale
import de.comahe.i18n4k.forLocaleTag
import de.comahe.i18n4k.language

/**
* Loads a messages array from a text file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ data class LocalizedStringNumber @JvmOverloads constructor(
private fun normalizeNumber(text: StringBuilder) {
for (i in text.indices) {
if (!text[i].isDigit())
text[i] = text[i].toLowerCase()
text[i] = text[i].lowercaseChar()
}
while (true) {
val plusSign = text.indexOf("+")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class CompositeLocalizedStringTest {
fun init() {
i18n4k = i18n4kConfig
i18n4kConfig.restoreDefaultSettings()
i18n4kConfig.locale = Locale("en")
i18n4kConfig.locale = createLocale("en")

MessageTest1.unregisterAllTranslations()
MessageTest1.registerTranslation(MessagesTest1_en)
Expand Down
12 changes: 6 additions & 6 deletions i18n4k-core/src/commonTest/kotlin/de/comahe/i18n4k/LocaleTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class LocaleTest {

@Test
fun testLanguage() {
val locale = Locale("de")
val locale = createLocale("de")
assertEquals("de", locale.language)
assertEquals("", locale.country)
assertEquals("", locale.variant)
Expand All @@ -19,7 +19,7 @@ class LocaleTest {

@Test
fun testLanguageAndCountry() {
val locale = Locale("de", "AT")
val locale = createLocale("de", null, "AT")
assertEquals("de", locale.language)
assertEquals("AT", locale.country)
assertEquals("", locale.variant)
Expand All @@ -29,7 +29,7 @@ class LocaleTest {

@Test
fun testLanguageCountryAndVariant() {
val locale = Locale("de", "AT", "gaudi")
val locale = createLocale("de", null, "AT", "gaudi")
assertEquals("de", locale.language)
assertEquals("AT", locale.country)
assertEquals("gaudi", locale.variant)
Expand All @@ -38,14 +38,14 @@ class LocaleTest {

@Test
fun testLessSpecificLocale() {
val locale3 = Locale("de", "AT", "gaudi")
val locale3 = createLocale("de", null, "AT", "gaudi")
val locale2 = locale3.lessSpecificLocale
assertNotNull(locale2)
val locale1 = locale2.lessSpecificLocale
assertNotNull(locale1)

assertEquals(Locale("de", "AT"), locale2)
assertEquals(Locale("de"), locale1)
assertEquals(createLocale("de", null, "AT"), locale2)
assertEquals(createLocale("de"), locale1)
assertEquals(rootLocale, locale1.lessSpecificLocale)

// cache should be used
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class LocaleUtilsTest {

assertEquals(
"norsk (Norge,nynorsk)",
Locale("no", "NO", "NY").getDisplayNameInLocale()
createLocale("no", null, "NO", "nynorsk").getDisplayNameInLocale()
)
assertEquals(
"norsk (Norge)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class LocalizedStringNumberTest {
fun init() {
i18n4k = i18n4kConfig
i18n4kConfig.restoreDefaultSettings()
i18n4kConfig.locale = Locale("en")
i18n4kConfig.locale = createLocale("en")
}


Expand Down Expand Up @@ -167,7 +167,7 @@ class LocalizedStringNumberTest {

@Test
fun formatGermanTest() {
i18n4kConfig.locale = Locale("de")
i18n4kConfig.locale = createLocale("de")

assertEquals("123.456,789", LocalizedStringNumber(123_456.789).toString())
}
Expand Down
Loading
Loading