string-resource-format-limits

Installation
SKILL.md

The resource joins pieces; it does not format them

The multiplatform resource lookup understands %1$s and %1$d. It does not understand the flag and width part of a specifier, it has no escape for a literal percent sign, and it will not round, truncate or pad anything. Write %1$02d:00 in a resource and the specifier reaches the screen as text.

So the split is fixed: every value is finished in code, and the resource only concatenates.

// adapted — zero-padded here, because the resource cannot do it
private fun hourLabel(hour: Int): String = "${hour.toString().padStart(2, '0')}:00"

// the resource is literally "%1$s – %2$s"
stringResource(Res.string.hour_span, hourLabel(peak), hourLabel((peak + 1) % 24))

The same rule is why a percentage is built as "$coverage%" in Kotlin and handed in as a string: the % sign cannot survive in the resource, so it travels inside the argument.

Installs
2
GitHub Stars
35
First Seen
6 days ago
string-resource-format-limits — maxrave-dev/kotlin-footguns