Easy Localization: Localization key [...] not found
Asked Answered
S

3

21

I am using easy_localization: ^2.3.3 in a flutter project with CSV loader. When I build it is not able to find keys and it gives "Easy Localization: Localization key [...] not found". Any ideas why is this happening?


runApp(EasyLocalization(
    supportedLocales: [
      Locale('en', ''),
      Locale('it', ''),
      Locale('es', ''),
      Locale('de', ''),
      Locale('fr', ''),
      Locale('pt', ''),
    ],
    path: 'resources/langs/langs.csv',
    fallbackLocale: Locale('en', ''),
    saveLocale: false,
    useOnlyLangCode: true,
    assetLoader: CsvAssetLoader(),
    child: MyApp(status),
  ));
}

Susumu answered 4/12, 2020 at 9:37 Comment(3)
might be related to this bug: github.com/aissat/easy_localization/issues/205Susumu
Have you done the other installation steps? - Create folder and add translation files - Declare your assets localization directory in pubspec.yaml - etc. pub.dev/packages/easy_localizationUpsetting
I have, I found the solution though. answering right now.Susumu
S
1

I found a solution looking at this bug: https://github.com/aissat/easy_localization/issues/190#

I added the following:

dependencies:
  easy_localization_loader:
    git:
      url: git://github.com/aissat/easy_localization_loader.git
      ref: overman-dev

then I did a

flutter pub upgrade

and also changed the code into this

runApp(EasyLocalization(
    supportedLocales: [
      Locale('en'),
      Locale('it'),
      Locale('es'),
      Locale('de'),
      Locale('fr'),
      Locale('pt'),
    ],
    path: 'resources/langs/langs.csv',
    fallbackLocale: Locale('en'),
    saveLocale: false,
    useOnlyLangCode: true,
    assetLoader: CsvAssetLoader(),
    child: MyApp(status),
  ));

It worked.

Susumu answered 4/12, 2020 at 13:22 Comment(2)
Kindly share your langs.csv file which has 2-3 keywords with translated words. ThanksTerrel
Your above suggested solution worked. I was trying with Locale('en_US') because I have used it in my old project, this may be possible new version of this package only supports Locale('en'). Thanks dear.Terrel
O
41

Also this error can be happen for not setting the material app; I mean, I got same error for forgeting the add these lines to my material app;

MaterialApp(
    locale: context.locale,
    supportedLocales: context.supportedLocales,
    localizationsDelegates: context.localizationDelegates,
  ),

and my problem solved !

Oppression answered 13/4, 2021 at 11:28 Comment(2)
This should be an accepted answer. Thanks a lot!Redmund
It is important to note, in case you wrapped the EasyLocalization widget around the MaterialApp widget, that you also wrap the MaterialApp with a Builder widget so the context gets updated with the easy localization data correctlyAirdrie
L
4

You need to import import 'package:easy_localization/easy_localization.dart';

And add in your MaterialApp :

locale: context.locale,
supportedLocales: context.supportedLocales,
localizationsDelegates: context.localizationDelegates,
Lewendal answered 22/7, 2021 at 7:0 Comment(1)
without import, it won't even build the apk.Wooden
S
1

I found a solution looking at this bug: https://github.com/aissat/easy_localization/issues/190#

I added the following:

dependencies:
  easy_localization_loader:
    git:
      url: git://github.com/aissat/easy_localization_loader.git
      ref: overman-dev

then I did a

flutter pub upgrade

and also changed the code into this

runApp(EasyLocalization(
    supportedLocales: [
      Locale('en'),
      Locale('it'),
      Locale('es'),
      Locale('de'),
      Locale('fr'),
      Locale('pt'),
    ],
    path: 'resources/langs/langs.csv',
    fallbackLocale: Locale('en'),
    saveLocale: false,
    useOnlyLangCode: true,
    assetLoader: CsvAssetLoader(),
    child: MyApp(status),
  ));

It worked.

Susumu answered 4/12, 2020 at 13:22 Comment(2)
Kindly share your langs.csv file which has 2-3 keywords with translated words. ThanksTerrel
Your above suggested solution worked. I was trying with Locale('en_US') because I have used it in my old project, this may be possible new version of this package only supports Locale('en'). Thanks dear.Terrel

© 2022 - 2024 — McMap. All rights reserved.