What about strings without parameters?
As far as i understand Paraphrase aims to generate these methods for strings that use ICU message format. But what about simple strings without any arguments?
My use-case is that we used a string without arguments, that later was changed to have 1 argument. But if we use R.strings for these cases, then we cannot detect such change. Reverse is possible to detect, thanks to Paraphrase.
<string name="test_string">Bagels are tasty</string>
<string name="test_argument">bagel count: {0}</string>
<string name="test_plural">{count, plural, one {# tasty bagel} other {# tasty bagels}}
Seems a like pretty compelling argument
Great question!
We could start generating accessors for string resources without arguments. Something like:
object FormattedResources {
@StringRes val test_string: Int = R.string.test_string
fun test_argument(arg0: Any): StringResource = ...
fun test_plural(count: Number): StringResource = ...
}
Then if we added an argument, the val would turn into a fun and we would get a compile error.
I suspect that in most Android projects, a majority of the string resources will have no arguments. So it might be a little weird to access everything through a class called FormattedResources. But maybe not? Or maybe we could rename it StringResources?
Another option would be something like a lint rule that warns us if we make a getString call with missing arguments.