Can we dynamically change whole app language in flutter?

267 views Asked by At

I want my flutter application to be in French fr language. Yes, we can define translations file & manually do all the translations of the app texts & then translate them based on the locale..

But the issue is that the text is coming from firebase (which is added to firebase from dashboard) & it will contain text that isn't already defined in our translations file. so what do we do here ?

Is there anything in flutter to tackle this issue ? IF yes what is it ? IF NO what are the alternatives in this case, if any..

Thank You!!

1

There are 1 answers

1
Phoenix On

Yes you can. You need to use a Provider with a Model that implements a ChangeNotifier and use the package intl to provide the translated text that will be showed. And finally, when you want to put a text in your program, you don't hardcode it but you call a function like this AppLocalizations.of(context)!.youreright to show the text, and it will be translated based on the data stored in yout model provider and the text that you wrote in the .arb file. It's a lot to explain here, i'll put some links that explain better.

https://docs.flutter.dev/ui/accessibility-and-internationalization/internationalization

https://phrase.com/blog/posts/flutter-localization/