compose-multiplatform icon indicating copy to clipboard operation
compose-multiplatform copied to clipboard

How to switch between Languages Programitically

Open JagadishaIncture opened this issue 1 year ago • 9 comments

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 Screenshot 2024-02-22 at 4 57 51 PM

JagadishaIncture avatar Feb 22 '24 11:02 JagadishaIncture

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.

dima-avdeev-jb avatar Feb 22 '24 15:02 dima-avdeev-jb

when can we expect this change?

JagadishaIncture avatar Feb 23 '24 06:02 JagadishaIncture

CompositionLocal changes locals only for @Composables What about reading strings from ViewModels, Widgets ? @dima-avdeev-jb

rsktash avatar Feb 23 '24 14:02 rsktash

What about reading strings from ViewModels, Widgets ?

@rustamsmax Thanks, good question. We should discuss it.

dima-avdeev-jb avatar Feb 24 '24 05:02 dima-avdeev-jb

Any progress on this issue?

dhng22 avatar May 04 '24 19:05 dhng22

I'm interested in this feature too

toaster217 avatar May 08 '24 08:05 toaster217

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.

Melodeiro avatar Jun 24 '24 17:06 Melodeiro

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 avatar Jun 25 '24 09:06 terrakok

@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

ahmedhosnypro avatar Jun 25 '24 12:06 ahmedhosnypro

Is there a ticket on Youtrack for this issue?

dhng22 avatar Jul 22 '24 13:07 dhng22

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!

Vocaloid2048 avatar Aug 12 '24 04:08 Vocaloid2048

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.

okushnikov avatar Aug 26 '24 13:08 okushnikov

Sorry for the same bothering, is there have any possible way to do it now? Instead of editting Libuary's source code?

Vocaloid2048 avatar Sep 23 '24 09:09 Vocaloid2048