Skip to content

Commit d26537d

Browse files
authored
Merge pull request #801 from Tetraquark/#800
#800 Fix ResourceFormattedStringDesc.localized with StringDesc args
2 parents 0b16b7a + 79bfd4a commit d26537d

File tree

12 files changed

+59
-11
lines changed

12 files changed

+59
-11
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ buildscript {
6464
}
6565
6666
dependencies {
67-
classpath "dev.icerock.moko:resources-generator:0.24.4"
67+
classpath "dev.icerock.moko:resources-generator:0.24.5"
6868
}
6969
}
7070
@@ -82,10 +82,10 @@ project build.gradle
8282
apply plugin: "dev.icerock.mobile.multiplatform-resources"
8383
8484
dependencies {
85-
commonMainApi("dev.icerock.moko:resources:0.24.4")
86-
commonMainApi("dev.icerock.moko:resources-compose:0.24.4") // for compose multiplatform
85+
commonMainApi("dev.icerock.moko:resources:0.24.5")
86+
commonMainApi("dev.icerock.moko:resources-compose:0.24.5") // for compose multiplatform
8787
88-
commonTestImplementation("dev.icerock.moko:resources-test:0.24.4")
88+
commonTestImplementation("dev.icerock.moko:resources-test:0.24.5")
8989
}
9090
9191
multiplatformResources {
@@ -132,7 +132,7 @@ should [add `export` declarations](https://kotlinlang.org/docs/multiplatform-bui
132132

133133
```
134134
framework {
135-
export("dev.icerock.moko:resources:0.24.4")
135+
export("dev.icerock.moko:resources:0.24.5")
136136
export("dev.icerock.moko:graphics:0.9.0") // toUIColor here
137137
}
138138
```

gradle/moko.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[versions]
2-
resourcesVersion = "0.24.4"
2+
resourcesVersion = "0.24.5"
33

44
[libraries]
55
resources = { module = "dev.icerock.moko:resources", version.ref = "resourcesVersion" }

resources/src/jsMain/kotlin/dev/icerock/moko/resources/desc/PluralFormattedStringDesc.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@ actual data class PluralFormattedStringDesc actual constructor(
1616
override suspend fun toLocalizedString(): String =
1717
toLocalizedString(pluralsRes.loader.getOrLoad())
1818

19+
@Suppress("SpreadOperator")
1920
override fun toLocalizedString(provider: JsStringProvider): String {
2021
return pluralsRes.localized(
2122
provider = provider,
2223
locale = StringDesc.localeType.locale,
2324
quantity = number,
24-
args = args.toTypedArray()
25+
*Utils.processArgs(args, provider)
2526
)
2627
}
2728
}

resources/src/jsMain/kotlin/dev/icerock/moko/resources/desc/ResourceFormattedStringDesc.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ actual data class ResourceFormattedStringDesc actual constructor(
1414
override suspend fun toLocalizedString(): String =
1515
toLocalizedString(stringRes.loader.getOrLoad())
1616

17+
@Suppress("SpreadOperator")
1718
override fun toLocalizedString(provider: JsStringProvider): String {
1819
return stringRes.localized(
1920
provider = provider,
2021
locale = StringDesc.localeType.locale,
21-
args = args.toTypedArray()
22+
*Utils.processArgs(args, provider)
2223
)
2324
}
2425
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Copyright 2025 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
package dev.icerock.moko.resources.desc
6+
7+
import dev.icerock.moko.resources.provider.JsStringProvider
8+
9+
object Utils {
10+
fun processArgs(
11+
args: List<Any>,
12+
provider: JsStringProvider
13+
): Array<out Any> {
14+
return args.map { (it as? StringDesc)?.toLocalizedString(provider) ?: it }.toTypedArray()
15+
}
16+
}

resources/src/jvmMain/kotlin/dev/icerock/moko/resources/desc/PluralFormattedStringDesc.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ actual data class PluralFormattedStringDesc actual constructor(
1111
val number: Int,
1212
val args: List<Any>
1313
) : StringDesc {
14-
14+
@Suppress("SpreadOperator")
1515
override fun localized() = pluralsRes.localized(
1616
locale = StringDesc.localeType.currentLocale,
1717
quantity = number,
18-
*(args.toTypedArray())
18+
*Utils.processArgs(args)
1919
)
2020
}

resources/src/jvmMain/kotlin/dev/icerock/moko/resources/desc/ResourceFormattedStringDesc.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ actual data class ResourceFormattedStringDesc actual constructor(
1010
private val stringRes: StringResource,
1111
private val args: List<Any>
1212
) : StringDesc {
13+
@Suppress("SpreadOperator")
1314
override fun localized() = stringRes.localized(
1415
locale = StringDesc.localeType.currentLocale,
15-
*(args.toTypedArray())
16+
*Utils.processArgs(args)
1617
)
1718
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
* Copyright 2025 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
package dev.icerock.moko.resources.desc
6+
7+
object Utils {
8+
fun processArgs(args: List<Any>): Array<out Any> {
9+
return args.map { (it as? StringDesc)?.localized() ?: it }.toTypedArray()
10+
}
11+
}

samples/resources-gallery/mpp-library/src/commonMain/moko-resources/base/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@
88
<string name="quotes">Alex009 said "hello world" &amp; "write tests".</string>
99
<string name="single_quotes">Alex009 said 'hello'</string>
1010
<string name="text_only_in_base">Text from base locale</string>
11+
<string name="hello_formatted_string">Hello %s</string>
1112
</resources>

samples/resources-gallery/mpp-library/src/commonMain/moko-resources/ru/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@
1212
<string name="quotes">Alex009 сказал "привет мир" &amp; "пишите тесты".</string>
1313
<string name="single_quotes">Alex009 сказал 'привет'</string>
1414
<string name="test.dialect">Russian</string>
15+
<string name="hello_formatted_string">Привет %s</string>
1516
</resources>

0 commit comments

Comments
 (0)