JetBrains / compose-multiplatform

Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.
https://jetbrains.com/lp/compose-multiplatform
Apache License 2.0
16.15k stars 1.17k forks source link

Plural quantity placeholder not working correctly #4675

Closed FunkyMuse closed 6 months ago

FunkyMuse commented 6 months ago

Describe the bug Plural quantity placeholder is not respected

Affected platforms

Versions

To Reproduce Steps and/or the code snippet to reproduce the behavior:

Downloading Downloading 1 file Downloading %1$d files
2.
```kotlin
val newValue = 10
val textToShow = getPluralString(
                            resource = Res.plurals.downloading_files,
                            quantity = newValue
                        )

// or when used in Compose manner

val text = pluralStringResource(Res.plurals.downloading_files, 10)

It just displays the placeholder Downloading %1$d files

Expected behavior The text should show Downloading 10 files

Screenshots Screenshot_20240422_195045_Berg

terrakok commented 6 months ago

There is third parameter for arguments:

fun pluralStringResource(resource: PluralStringResource, quantity: Int, vararg formatArgs: Any): String {...}

You are supposed to use val text = pluralStringResource(Res.plurals.downloading_files, 10, 10)

b0r1ngx commented 5 months ago

Hello, interesting why the first one is needed, when we provide just resource and quantity?

paxbun commented 5 months ago

@b0r1ngx The design is an imitation of Android's plural string resource. We can't decide which argument should be used as the quantity when there are multiple format arguments.

@terrakok, the plural string example in the new documentation provides a code without format arguments.

Text(pluralStringResource(Res.string.new_message, 1))

I think the third formatArgs argument should be noted to make fewer people confused.

okushnikov commented 3 months ago

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.