localizely / intl_utils

Dart package that creates a binding between your translations from .arb files and your Flutter app
BSD 3-Clause "New" or "Revised" License
135 stars 81 forks source link

Localizations.override override the whole app #19

Open EdwynZN opened 3 years ago

EdwynZN commented 3 years ago

Perhaps this is a problem with flutter itself and not this awesome package but maybe you can help me narrow the problem so I can open the issue in the Flutter project instead (There is already a similar problem in Flutter issues https://github.com/flutter/flutter/issues/33300)

When using AboutListTile() > Opening Dialog > See Licenses > Tap on any License the Localization becomes English for the whole app, Reading the code they use Localizations.override(locale: const Locale('en', 'US'), ...) so the license page load only in English, the problem is that Localizations.override should only override that page, but it changes the whole app language to English


void main() {
  runApp(const App());
}

// Run the app in other language (Spanish) and after opening licenses and visualizes one

class Appextends StatelessWidget {
  const GameShop({Key key}) : super(key: key);

  @override
  Widget build(BuildContext contexth) {
    return MaterialApp(
      localizationsDelegates: [
        S.delegate,
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
      ],
      supportedLocales: S.delegate.supportedLocales,
      home: Builder(
          builder: (context) => Scaffold(
              body: AboutListTile(
                  applicationName: S.of(context).example_text
              ),
          )
      ),
    );
  }
}
[√] Flutter (Channel stable, 1.22.5, on Microsoft Windows [Versión 10.0.18363.1316], locale es-MX)
    • Flutter version 1.22.5 at E:\Programs\flutter
    • Framework revision 7891006299 (5 weeks ago), 2020-12-10 11:54:40 -0800
    • Engine revision ae90085a84
    • Dart version 2.10.4

[√] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
    • Android SDK at C:\Users\dartz\AppData\Local\Android\Sdk
    • Platform android-30, build-tools 30.0.2
    • ANDROID_HOME = C:\Users\dartz\AppData\Local\Android\Sdk
    • Java binary at: E:\Programs\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
    • All Android licenses accepted.

[!] Android Studio (version 4.1.0)
    • Android Studio at E:\Programs\Android\Android Studio
    X Flutter plugin not installed; this adds Flutter specific functionality.
    X Dart plugin not installed; this adds Dart specific functionality.
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
aleksakrstic commented 3 years ago

Hi @EdwynZN This is a known problem. Linked issues from IDE plugins:

PR is created https://github.com/localizely/intl_utils/pull/18 but I think such changes should be considered for the next major version

narumi147 commented 2 years ago

At least, we should not assign the new locale in S.load, this is called in each Localizations.override. Let developer to choose when to assign new locale.