moko-resources icon indicating copy to clipboard operation
moko-resources copied to clipboard

Formatted strings in iOS with $s placeholders

Open cw-communiski opened this issue 2 years ago • 2 comments

I cannot figure out how to get strings with placeholders in the iOS app. I believe the issue I'm having is due to the strings using placeholders in the format "%1$s" when iOS requires the format "%1$@"

This is how I'm getting the strings in swiftUI at present: let string = SharedRes.strings().text_dont_have_account.localized()

When I try to replace this with: let string = String(format:SharedRes.strings().text_dont_have_account.localized(), arguments:["TEST"]) I get an error.

Here's the string resource: <string name="text_dont_have_account">Don\'t have an account? %1$s</string> and if I change this to <string name="text_dont_have_account">Don\'t have an account? %1$@</string> It works on iOS, but causes the Android app to crash.

What am I doing wrong here? How do I use strings with placeholders across both platforms?

cw-communiski avatar May 12 '23 21:05 cw-communiski

hi! in past we implement support of positional arguments and it works. https://github.com/icerockdev/moko-resources/blob/15fadd5ff058a967b0980daaebc48bb76e6cf465/samples/resources-gallery/mpp-library/src/commonMain/resources/MR/base/strings.xml#L6 here resource declaration https://github.com/icerockdev/moko-resources/blob/15fadd5ff058a967b0980daaebc48bb76e6cf465/samples/resources-gallery/mpp-library/src/commonTest/kotlin/com/icerock/library/StringResourceTests.kt#L46 here test that run on every pull request on android & ios. last run shows successful test result image

please compare your implementation with samples. if you not find solution - please create minimal project reproducer

Alex009 avatar May 15 '23 06:05 Alex009

I have the exact same problem as @cw-communiski. I guess that we are not using localized strings on the ios side as they are planned to be used.

@Alex009 can you give an example on how to use formatted strings on ios? (The readme only shows how to use them from common part.)

geckogecko avatar Feb 17 '24 16:02 geckogecko