https://github.com/bb441db/compose-strings-plugin
Generate Type-Safe Composable Functions for Android String Resources
https://github.com/bb441db/compose-strings-plugin
Last synced: 8 months ago
JSON representation
Generate Type-Safe Composable Functions for Android String Resources
- Host: GitHub
- URL: https://github.com/bb441db/compose-strings-plugin
- Owner: bb441db
- Created: 2022-03-26T21:48:46.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-03-26T22:05:03.000Z (about 4 years ago)
- Last Synced: 2025-08-03T12:46:01.170Z (10 months ago)
- Language: Kotlin
- Size: 111 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Compose Strings Plugin
## Example Usage
```xml
Hello %1$s!
World
```
```kt
// String resource without any format specifiers will become getters
@Composable
fun MainView() {
Greeter(name = Strings.Main.world)
}
// Resources with at least one format specifier will become a composable function
@Composable
fun Greeter(name: String) {
Text(text = Strings.Main.hello(p1 = name))
}
```
## Generated Code Example
```kt
public object Strings {
public object App {
public val name: String
@Composable
get() = stringResource(id = R.string.app_name)
}
public object Main {
public val world: String
@Composable
get() = stringResource(id = R.string.main_world)
@Composable
public fun hello(p1: String): String = stringResource(id = R.string.main_hello, p1)
}
}
```
## TODOs
* Convert generated `object`'s to `namespace` when added to kotlin [KT-11968](https://youtrack.jetbrains.com/issue/KT-11968)
* Named arguments instead of p1, p2, p3...
* Copy comments in XML file to the generated functions