Easy_localization: Need to setstat to refresh translation

Created on 2 Apr 2020  路  4Comments  路  Source: aissat/easy_localization

I am using a button in drawer to change lange from arabic to english,
here is the code onTap ,

                          onTap: () {
                            if (EasyLocalization.of(context)
                                    .locale
                                    .languageCode ==
                                'ar') {
                              EasyLocalization.of(context).locale =
                                  Locale('en');
                            } else {
                              EasyLocalization.of(context).locale =
                                  Locale('ar');
                            }
                            Navigator.pop(context);
                          }

why it need to hot reload app to apply changes

Most helpful comment

It works fine except that it needs to rebuild the app after change language, I found this solution to rebuild app after changing language by calling this method in language button .

  void rebuildAllChildren(BuildContext context) {
    void rebuild(Element el) {
      el.markNeedsBuild();
      el.visitChildren(rebuild);
    }

    (context as Element).visitChildren(rebuild);
  }

All 4 comments

@fatimahossny this #116 resolve ur issues

It works fine except that it needs to rebuild the app after change language, I found this solution to rebuild app after changing language by calling this method in language button .

  void rebuildAllChildren(BuildContext context) {
    void rebuild(Element el) {
      el.markNeedsBuild();
      el.visitChildren(rebuild);
    }

    (context as Element).visitChildren(rebuild);
  }

next version don't need do

void rebuildAllChildren(BuildContext context) {
    void rebuild(Element el) {
      el.markNeedsBuild();
      el.visitChildren(rebuild);
    }

    (context as Element).visitChildren(rebuild);
  }

just like this code will be work well

onPressed: () {
                EasyLocalization.of(context).locale.languageCode !='ar' 
                ? EasyLocalization.of(context).locale = EasyLocalization.of(context).supportedLocales[1]
                : EasyLocalization.of(context).locale =EasyLocalization.of(context).supportedLocales[0];

              },

@aissat Still some data is not translated

Was this page helpful?
0 / 5 - 0 ratings

Related issues

liudonghua123 picture liudonghua123  路  7Comments

gjrjf picture gjrjf  路  4Comments

Melak12 picture Melak12  路  4Comments

Jerrywyx picture Jerrywyx  路  4Comments

KarlChow92 picture KarlChow92  路  3Comments