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

Support for string-array

Open ln-12 opened this issue 4 years ago • 4 comments

In Android I can use string-array in XML code like the following:

<string-array name="someArray">
    <item>Item 1</item>
    <item>Item 2</item>
</string-array>

Would it be possible to support it in this library?

ln-12 avatar Apr 21 '21 08:04 ln-12

i not sure that on iOS we have analog. need to research

Alex009 avatar May 10 '21 10:05 Alex009

I don't think that there is an equivalent for iOS, but it might be possible to implement the behavior in a different way. Maybe by doing something like adding the strings as someArray_1, someArray_2, etc. in the strings files and providing it as

actual val someArray: Array<StringResource> = arrayOf(StringResource(R.string.someArray_1), StringResource(R.string.someArray_2))

respectively

actual val someArray: Array<StringResource> = arrayOf(StringResource(resourceId = "someArray_1", bundle = bundle), StringResource(resourceId = "someArray_2", bundle = bundle))

instead of plain StringResource. One could then iterate over someArray to get all values. What do you think of that approach?

ln-12 avatar May 11 '21 10:05 ln-12

It would be great if you follow up adding support for string arrays to the lib. That would make the lib even more valuable for KMM projects.

ChristOpp avatar Mar 25 '22 08:03 ChristOpp

Hello! Any updates on this? :)

EDIT:

@ln-12 As a workaround, I used something similar to what you suggested, I broke my array into separate strings with the same prefix, and then used the arrayOf, it might not be optimized, or flexible, but it works

val choicesArray = arrayOf(
    getString(R.string.choices_option_1),
    getString(R.string.choices_option_2)
)

So, I think for iOS it would work as a workaround, if the generator would take care of this boilerplate. For android, the default api can still be used

tamimattafi avatar Jan 09 '24 07:01 tamimattafi