Can anyone recommend a KMP library for string reso...
# multiplatform
j
Can anyone recommend a KMP library for string resources? I have a Compose app where certain pieces of code need to be able to run in headless mode, which Compose resources doesn't support (CMP-8068). I see issue KT-63189 but am wondering if there's a 3rd party option. I only need simple retrieval of static strings.
j
Im not sure if im understanding hte question but if yes : you are trying to sometimes use a string resource and sometimes use a (potentially empt) dymamic resource to which you can just send a string. for this purpose I did the following simple class:
Copy code
actual sealed class StringHolderKMP {
    data class Dynamic(val value: String) : StringHolderKMP()
    data class Resource(val string: StringResource, val args: List<Any> = emptyList()) : StringHolderKMP()
}
and then this helper function within a @composable context
Copy code
return when (str) {
        is StringHolderKMP.Dynamic -> str.value
        is StringHolderKMP.Resource -> {
            if (str.args.isEmpty()) {
                stringResource(str.string)
            } else {
                stringResource(str.string, *str.args.toTypedArray())
            }
        }
this way a variable like for example an error message, could be passed via a translated resource if we have it, but can also just take the message from the server which isnt translatted and pass it as a dynamic. Its probably not recommended, I don't know what im doing.
j
You can have a look my library, I'm using it in my project https://github.com/jbruchanov/kostra