Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need callback finish EasyLocalization -> Load asset from assets/translations #650

Open
DmitriySimonov opened this issue Feb 22, 2024 · 0 comments

Comments

@DmitriySimonov
Copy link

DmitriySimonov commented Feb 22, 2024

easy_localization: ^3.0.4

There is a problem, I need to know at what point the final initialization of Easy Localization will take place.

Why? When I start the application, I create a notification (+background service) and it starts BEFORE the final initialization of Easy Localization, because of this, instead of translations, I see keys....

And to create my notification with translations, I need to know the moment at which translations will be available (finish init EasyLocalization).

изображение

Code example:

main() async {
  WidgetsBinding widgetsBinding = WidgetsFlutterBinding.ensureInitialized();

  //await EasyLocalization.ensureInitialized();
  //-------------------
  //LocaleKeys.name.tr(); // <--- Not working!
  // [34m[🌎 Easy Localization] [WARNING] Localization key [name] not found
  //-------------------

  // Need await Widget app = EasyLocalization(...

  Widget app = EasyLocalization(
    supportedLocales: LocalizationConfiguration().supportedLocales,
    path: LocalizationConfiguration().path,
    fallbackLocale: LocalizationConfiguration().fallbackLocale,
    saveLocale: true,
    child: const App(),
  );

  runApp(app);

  /*
  I/flutter (13538): [🌎 Easy Localization] [DEBUG] Start\
  I/flutter (13538): [🌎 Easy Localization] [DEBUG] Init state
  I/flutter (13538): [🌎 Easy Localization] [INFO] Saved locale loaded ru
  I/flutter (13538): [🌎 Easy Localization] [DEBUG] Build
  I/flutter (13538): [🌎 Easy Localization] [DEBUG] Init Localization Delegate
  I/flutter (13538): [🌎 Easy Localization] [DEBUG] Init provider
  I/flutter (13538): [🌎 Easy Localization] [DEBUG] Load Localization Delegate
  I/flutter (13538): [🌎 Easy Localization] [DEBUG] Load asset from assets/translations
   */

  // and only then can we use LocaleKeys.name.tr();
}

flutter doctor

[✓] Flutter (Channel stable, 3.19.0, on Ubuntu 22.04.3 LTS 5.15.0-94-generic, locale ru_RU.UTF-8)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0-rc1)
[✓] Chrome - develop for the web
[✓] Linux toolchain - develop for Linux desktop
[✓] Android Studio (version 2023.1)
[✓] IntelliJ IDEA Ultimate Edition (version 2023.2)
[✓] Connected device (3 available)
[✓] Network resources
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant