Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(non-compose-accessors): add non compose accessors #40

Merged
merged 2 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ internal class LyricistSymbolProcessor(
|) {
| ProvideStrings(lyricist, Local$fileName, content)
|}
|
|$visibility fun getLocale$fileName(locale: Locale = Locale.current): $stringsClassOutput {
| return $stringsName[locale.toLanguageTag()] ?: $defaultStringsOutput
|}
""".trimMargin().toByteArray()
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,14 @@ internal class LyricistXmlSymbolProcessor(
""".trimMargin().toByteArray()
)
}
stream.write(
"""
|
|public fun getLocale$fileName(locale: Locale = Locale.current): $fileName {
| return $stringsName[locale.toLanguageTag()] ?: $defaultStringsOutput
|}
""".trimMargin().toByteArray()
)
}
}

Expand Down
26 changes: 26 additions & 0 deletions sample/src/main/java/cafe/adriel/lyricist/sample/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cafe.adriel.lyricist.sample

import android.os.Bundle
import android.widget.Toast
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.Arrangement
Expand All @@ -27,6 +28,7 @@ import cafe.adriel.lyricist.XmlStrings
import cafe.adriel.lyricist.custompackage.LocalMultiModuleStrings
import cafe.adriel.lyricist.custompackage.ProvideMultiModuleStrings
import cafe.adriel.lyricist.custompackage.rememberMultiModuleStrings
import cafe.adriel.lyricist.getLocaleStrings
import cafe.adriel.lyricist.rememberStrings
import cafe.adriel.lyricist.rememberXmlStrings
import cafe.adriel.lyricist.sample.multimodule.strings.MultiModuleStrings
Expand Down Expand Up @@ -70,7 +72,14 @@ class MainActivity : ComponentActivity() {
SampleXmlStrings()
}
}

item {
Row(modifier = Modifier.padding(vertical = 16.dp)) {
ShowToastButton()
}
}
}

Row(
horizontalArrangement = Arrangement.SpaceEvenly,
modifier = Modifier
Expand Down Expand Up @@ -160,6 +169,23 @@ class MainActivity : ComponentActivity() {
}
}

@Composable
fun ShowToastButton(
modifier: Modifier = Modifier
) {
Button(
onClick = {
showToast()
}, modifier = modifier
) {
Text(text = "Show Toast")
}
}

private fun showToast() {
Toast.makeText(this, getLocaleStrings().nonComposeAlert, Toast.LENGTH_SHORT).show()
}

@Composable
fun SwitchLocaleButton(
languageTag: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,7 @@ internal val EnStrings = Strings(
"I have $value apples"
},

list = listOf("Avocado", "Pineapple", "Plum")
list = listOf("Avocado", "Pineapple", "Plum"),

nonComposeAlert = "This is a sample toast",
)
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,7 @@ internal val PtStrings = Strings(
"Eu $value maças"
},

list = listOf("Abacate", "Abacaxi", "Ameixa")
list = listOf("Abacate", "Abacaxi", "Ameixa"),

nonComposeAlert = "Este é um exemplo de brinde",
)
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ internal data class Strings(
val annotated: AnnotatedString,
val parameter: (locale: String) -> String,
val plural: (count: Int) -> String,
val list: List<String>
val list: List<String>,
val nonComposeAlert:String
)