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
15.99k stars 1.16k forks source link

String resource parsing works differently when compared to Android #4910

Closed Thomas-Vos closed 3 months ago

Thomas-Vos commented 4 months ago

Describe the bug There are some differences with string parsing with compose when compared to official string resources on Android:

1. Format args

It is possible to pass format args to org.jetbrains.compose.resources.stringResource. Great, but it doesn't work with:

On Android this does work. Example string:

<string name="last_updated_s">Last updated: %s</string>

Usage:

stringResource(R.string.last_updated_s, "test")

Expected output:

Last updated: test

2. Newlines

Example string:

<string name="test">Test1
\nTest2
\nTest3</string>

Expected output:

Test1
Test2
Test3

There are additional newlines in the output which is incorrect when compared to Android. On Android, a simple newline (not \n but literally a new line) is ignored.

3. Backslashes

Here are two strings:

<string name="test1">Test \"Test\" Test</string>
<string name="test2">Test \'Test\' Test</string>

On Android the output would be:

Test "Test" Test
Test 'Test' Test

But with compose the output still contains the backwards slashes.

Affected platforms All

Versions

Expected behavior Same behaviour as official Android strings.

terrakok commented 3 months ago

There are some differences with string parsing with compose when compared to official string resources on Android

Yes. It is by design

terrakok commented 3 months ago

1) You are suppose to use Res class for that and a slightly different format https://www.jetbrains.com/help/kotlin-multiplatform-dev/compose-images-resources.html#string-templates 2) Because you do have new lines and \n symbols in you text https://www.jetbrains.com/help/kotlin-multiplatform-dev/compose-images-resources.html#simple-strings 3) Because you are not suppose to use backslashes for that, just have a text in a clean form

Thomas-Vos commented 3 months ago

Alright, but in my project the strings are imported by translation services. They use the Android format. That compose works differently does make it more difficult.

okushnikov commented 2 months ago

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