msayed-net / localize_and_translate

Flutter localization in easy steps
MIT License
52 stars 22 forks source link

context.setLocale / context.setLanguageCode sometimes fail to change language #31

Open lunatigs opened 1 year ago

lunatigs commented 1 year ago

My app is using localize_and_translate: ^5.1.1 and has a dropdown that lets you change the language of the app, by doing

onChanged: (String? newLang) {
    context.setLocale(Locale(newLang.toLowerCase(), newLang.toUpperCase()));
    context.setLanguageCode(newLang.toLowerCase());
    setState(() {
        dropdownValue = newLang;
    });
},

That's actually a basic example, of course i check if newLang is null or not. Just kept it small so you get the idea.

Problem now is, this works about 99% fine and the language does change right away, but sometimes the language just isn't loaded. I get no exception, try-catch shows nothing, the language just isn't loaded sometimes and then 'whatever'.tr() will show "whatever" instead of the translation it should show.

I would expect at least an exception so i have a chance to react, but right now users just end up with an untranslated app sometimes, which of course does create problems.

msayed-net commented 11 months ago

Please add more details like what values in this newLang and why calling the two methods setLocale setLanguageCode one is enough

lunatigs commented 10 months ago

Answering all this doesn't clear up, why those methods fail silently in the case of an error, instead of throwing an exception you can react to.