-
-
Notifications
You must be signed in to change notification settings - Fork 18
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
Strings for language tag not found #10
Comments
Working example for you:
|
While that may appear to work it goes against the guidelines for Compose.
Setting the languageTag in the composable function like that is a side effect that will potentially rerun on every recomposition of the function, and after using |
When I was looking into it i found two issues when working with composeables.
Hopefully this shouldn't trigger any unnecessary recomposition except when the locale changes. @Composable
fun CustomProvideStrings(
content: @Composable () -> Unit,
) {
val locale: Locale = Locale.current
val tag = remember(locale) { locale.toLanguageTag() }
val lyricist = remember(tag) {
Lyricist("en"/* Default Tag*/, Strings).apply {
languageTag = tag
}
}
ProvideStrings(lyricist, content)
} |
Fixed on 1.6.0. I've replaced the val lyricist = rememberStrings(
defaultLanguageTag = "es-US", // Default value is the one annotated with @LyricistStrings(default = true)
currentLanguageTag = getCurrentLanguageTagFromLocalStorage(),
) Thanks everyone! |
Hi, I'm trying to use this library without the KSP generation and following the README for writing the code myself. However, following these instructions lead to an issue where the library doesn't fall back to the default I want if it can't find a match for the system language setting.
Minimal example:
I would expect this app to display "Hello world" if the locale is English, and "Hola mundo" if the locale is Spanish, and fallback to English if the locale is something else. As long as the locale is English or Spanish this seems to be the case:
All four US and UK English and Spanish combinations work as expected.
However, if I change the system language to something else, Portuguese, instead of falling back to English the app crashes.
I can see the default argument for
languageTag
inrememberStrings
isLocale.current.toLanguageTag()
, which gets passed into the instance ofLyricist
as thedefaultLanguageTag
. If I override that argument as in the commented code in the example above, I can force the language to English, which prevents the crash but also stops the localisation working for Spanish.The text was updated successfully, but these errors were encountered: