compose-multiplatform
compose-multiplatform copied to clipboard
How to switch between Languages Programitically
HI Team,
Iam working on feature to support multiple langs en and fr . so for that i've created two strings.xml one for (en) and other for (fr) and now I'm able to access string from english lang using below code
stringResource(Res.strings.by_product)
Feature : will be providing dropdown in Profile Screen to switch between lang . as soon user selects fr then i should be able to show strings from strings.xml(fr)
is there any way to programatically switch between lang
Thanks!
We discussed this feature in our team. One of possible solution is to provide staticCompositionLocal with with ability to override qualifiers in part of Compose hierarchy.
when can we expect this change?
CompositionLocal changes locals only for @Composables What about reading strings from ViewModels, Widgets ? @dima-avdeev-jb
What about reading strings from ViewModels, Widgets ?
@rustamsmax Thanks, good question. We should discuss it.
Any progress on this issue?
I'm interested in this feature too
I think thats an important feature, because otherwise your option is to provide the default language, if OS language does not match to anything you have. But its not guaranteed that the user will be comfortable with the default one.
@dima-avdeev-jb Why not to provide the composable changes with static provider if you think that is better, and non-composable, using a some kind of a property? Maybe within the application class, so we can make a callback to switch it.
We will implement the feature but it is not responsibility of the resources library. It will be done in the core/runtime modules. It requires approvals and some design decisions. So, have a patience 😉
@terrakok This comment might help at #4197 https://github.com/JetBrains/compose-multiplatform/issues/4197#issuecomment-2185561043
Also provides the solution for this question
CompositionLocal changes locals only for @composables What about reading strings from ViewModels, Widgets ? @dima-avdeev-jb
Is there a ticket on Youtrack for this issue?
Sorry for bothering, Is any news of that function? It will be awesome to use it in an official way. Anyway, thanks to everyone's hard work and effort in this useful function!
Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.
Sorry for the same bothering, is there have any possible way to do it now? Instead of editting Libuary's source code?