Jesway / flutter_translate

Flutter Translate is a fully featured localization / internationalization (i18n) library for Flutter.
MIT License
401 stars 118 forks source link

title and bottom navigation bar item not translate after setting local success. #38

Closed liudonghua123 closed 4 years ago

liudonghua123 commented 4 years ago

I have a page which contains some bottom navigationbar item and in one page, I set the locale and the strings of current page changed except the appbar title and bottom navigationbar items. I have to click any of the navigationbar item, then it changed. I simplify the code and make a demo on https://github.com/liudonghua123/redux_thunk_example/tree/flutter_translate.

It seems the same as using another translate package (easy_localization, https://github.com/aissat/easy_localization/issues/108).

liudonghua123 commented 4 years ago

Finally, I modified the following code to fix this. change changeLocale async, and in its implementation await delegate.changeLocale.

void changeLocale(BuildContext context, String localeCode) async
{
    if (localeCode != null)
    {
        await LocalizedApp.of(context).delegate.changeLocale(localeFromString(localeCode));

        LocalizationProvider.of(context).state.onLocaleChanged();
    }
}

And before dispatch local action, await changeLocale finish.

                await changeLocale(
                    context, '${locale.languageCode}_${locale.countryCode}');
                StoreProvider.of<AppState>(context)
                    .dispatch(LocaleAction(locale));
Mohamed-Rashed commented 2 years ago

not work with me