How StringDesc works and how to use it
masterA StringDesc is a multi-source container for strings. It can represent a resource, a plural, a formatted variant, or a raw string. This abstraction allows you to write logic in commonMain that decides what string to show, while leaving the how to render it to the platform-specific code.
Common Types of StringDesc:
StringDesc.Resource(MR.strings.key): A standard resource.StringDesc.ResourceFormatted(MR.strings.key, arg): A resource with arguments.StringDesc.Plural(MR.plurals.key, quantity): A plural resource.StringDesc.Raw(string): A plain, non-resource string.
Runtime Localization Control: You can force a specific locale in common code:
StringDesc.localeType = StringDesc.LocaleType.Custom("es")(e.g., for Spanish).StringDesc.localeType = StringDesc.LocaleType.System(returns to device settings).
// Example: Switching between a raw string and a resource
fun getUserName(user: User?): StringDesc {
return if (user != null) {
StringDesc.Raw(user.name)
} else {
StringDesc.Resource(MR.strings.name_placeholder)
}
}