On SwiftUI, when a user writes a code like the following:
Text("This is a sample text.")
SwiftUI automatically maps "This is a sample text" to another string defined in Localizable.strings. This can be done because Localizable.strings allows any string to be a key.
# Localizable.strings (Korean)
"This is a sample text." = "샘플 텍스트입니다."
This can also be achieved in Kotlin theoretically, as Kotlin supports non-standard identifiers with backticks (except for the unsupported ones due to JVM).
Text(stringResource(Res.strings.`This is a sample text`))
<string id="This is a sample text">This is a sample text.</string>
<string id="This is a sample text">샘플 텍스트입니다.</string>
Although on Android string IDs have used snake_case, and the IDE replaced the occurrences of such IDs with the actual content when rendering the code, allowing this helps programmers to worry about resource ID namings less and eventually improves their productivity. One can do something like:
@Composable
fun MyView(value: String) {
Text(stringResource(Res.strings.`MyView!The value is`, value))
}
so the human translators can easily find where and how the text is actually used.
However, the current implementation does not consider the case where non-standard identifiers are used as string resource IDs. To achieve this, $resName in the following should be escaped using the %N format specifier of Kotlinpoet's CodeBlock.
On SwiftUI, when a user writes a code like the following:
SwiftUI automatically maps
"This is a sample text"
to another string defined inLocalizable.strings
. This can be done becauseLocalizable.strings
allows any string to be a key.This can also be achieved in Kotlin theoretically, as Kotlin supports non-standard identifiers with backticks (except for the unsupported ones due to JVM).
Although on Android string IDs have used snake_case, and the IDE replaced the occurrences of such IDs with the actual content when rendering the code, allowing this helps programmers to worry about resource ID namings less and eventually improves their productivity. One can do something like:
so the human translators can easily find where and how the text is actually used.
However, the current implementation does not consider the case where non-standard identifiers are used as string resource IDs. To achieve this,
$resName
in the following should be escaped using the%N
format specifier of Kotlinpoet'sCodeBlock
.https://github.com/JetBrains/compose-multiplatform/blob/b32350459acceb9cca6b9e4422b7aaa051d9ae7d/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/resources/GeneratedResClassSpec.kt#L243
https://github.com/JetBrains/compose-multiplatform/blob/b32350459acceb9cca6b9e4422b7aaa051d9ae7d/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/resources/GeneratedResClassSpec.kt#L264
I'm not sure whether this is intended or not, so I file a new issue here.