Hello, Do you know if it's possible to change the ...
# multiplatform
l
Hello, Do you know if it's possible to change the app language programmatically when using Compose Multiplatform resources? I haven’t been able to find a clear answer 🤔
n
Hi, as Compose Multiplatform still dont support that i made gradle plugin for that. You can checkout in github: https://github.com/hyperether/compose-multiplatform-localize
l
Hey Nikola, thanks, it looks promising. I just added an issue, lmk if you have a fix
n
Great, thanks for checking out and write the issue. Yes, i didnt try with sublanguages. I will look into it. I think i will have time to fix it until friday.
🙌 1
z
We have a documentation page for this with Compose Multiplatform: https://www.jetbrains.com/help/kotlin-multiplatform-dev/compose-resource-environment.html It covers locale, theme, and density. I've only used the in-app theme switching functionality myself (you can find it in the KotlinConf app), but they all work very similarly afaik.
t
@Louis I am doing it a more manual and clunky way until something more industry standard comes out, and then I'll adopt that method of handling. My manual way reads the localization of the device and sets it to that language value (with a default to english if that language is not available) and then will allow the user to select a language in settings. I save it to the DataStore when the user sets it and check that first on app start. Datastore, if set, will overwrite the device localization language.
s
I follow below tutorial and it worked fine for me

https://www.youtube.com/watch?v=BrSnxbfxNOQ

thank you color 1
t
@Sarthak Sharma This is essentially what I'm doing manually as I have a centralized function to take in strings from various languages and it selects based on the language val set and passed in from the native platforms. The video you shared is a bit more abstracted and works a little closer to the Android traditional sense. Maybe next project I'll include it this way. Thanks for sharing!
🚀 1