easy_localization
easy_localization copied to clipboard
[🌎 Easy Localization] [WARNING] Localization key [key] not found
easy_localization: ^3.0.0
I have migrated my application to NullSafety and I have upgraded to the latest version of easy_localization. After the migration I am getting the following error in my console and the application is not displaying the values for my keys anymore. For every key in my json file I am getting the following error
[🌎 Easy Localization] [WARNING] Localization key [key] not found
Please note that this was working fine before the migration when I was using version 2.3.2.
My code is give below.
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await EasyLocalization.ensureInitialized();
final _navigatorKey = GlobalKey<NavigatorState>();
runApp(EasyLocalization(
supportedLocales: [
const Locale.fromSubtags(languageCode: "en"),
const Locale.fromSubtags(languageCode: "fr"),
const Locale.fromSubtags(languageCode: 'de'),
],
path: 'assets/lang',
fallbackLocale: Locale.fromSubtags(languageCode: 'en'),
startLocale: Locale.fromSubtags(languageCode: 'en'),
child: MultiProvider(
providers: [],
child: MaterialApp(
navigatorKey: _navigatorKey,
// home: SplashScreen(),
),
),
));
}
Startup log statements. [🌎 Easy Localization] [DEBUG] Localization initialized [🌎 Easy Localization] [DEBUG] Start [🌎 Easy Localization] [DEBUG] Init state [🌎 Easy Localization] [INFO] Start locale loaded en [🌎 Easy Localization] [DEBUG] Build [🌎 Easy Localization] [DEBUG] Init Localization Delegate [🌎 Easy Localization] [DEBUG] Init provider [🌎 Easy Localization] [WARNING] Localization key [select_your_language] not found [🌎 Easy Localization] [WARNING] Localization key [next_step] not found
I am getting the same error. However not for all of my translations only for a few of them.
For me the problem actually was that I was trying to access the localization before it was initialized. It has to be run after
runApp(
EasyLocalization(
...
Use localization here
...
)
)
I'm still experiencing the same issue, could you please provide a full code solution?
@petodavid Please check the following repo for the full code.
https://github.com/helloalbin/flutter_app/tree/easy_localization
I had the same issue, it seems like the EasyLocalization.ensureInitialized() does not wait for all initialization to complete (I await it and it does not work).
My workaround solution to wait for 1 second (with Future.delayed().then) before using the EasyLocalization plugin, this time allows the files to be initialized too.
@machiato32 Yes, that is what i figured out too. I moved my code which depends on the localization to a later point in my execution orde and now it is working for me.
But this is definitely a bug, which needs to be fixed.
Same problem. await ensureInitialized is the first line in main.
I get the same error too. i'm using easy_localization: ^3.0.0 this is my main function: `void main() async { WidgetsFlutterBinding.ensureInitialized();
await EasyLocalization.ensureInitialized(); runApp( EasyLocalization( supportedLocales: [Locale('fa', 'IR')], path: 'assets/translation', fallbackLocale: Locale('fa', 'IR'), startLocale: Locale('fa', 'IR'), child: MultiProvider( child: MyApp(), providers: providers, )), ); }`
here is the output of flutter doctor:
Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 2.0.2, on Mac OS X 10.15.7 19H15 darwin-x64, locale en-IR) [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3) [✓] Xcode - develop for iOS and macOS [✓] Chrome - develop for the web [✓] Android Studio (version 4.1) [✓] VS Code (version 1.58.0) [✓] Connected device (1 available)
• No issues found!
solved it by adding "await" before EasyLocalizationController.initEasyLocation(); on easy_localization_app.dart line 106. i'll request the merge.
solved it by adding "await" before EasyLocalizationController.initEasyLocation(); on easy_localization_app.dart line 106. i'll request the merge.
Does not work for me. How awaiting a function that returns a Future would help in awaiting it? You still have to await that future so its still that same future.
I solved it by adding the localization attributes in the MaterialApp() as stated in the readme on pub dev.
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:easy_localization/easy_localization.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await EasyLocalization.ensureInitialized();
runApp(
EasyLocalization(
supportedLocales: [Locale('en', 'US'), Locale('de', 'DE')],
path: 'assets/translations', // <-- change the path of the translation files
fallbackLocale: Locale('en', 'US'),
child: MyApp()
),
);
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
localizationsDelegates: context.localizationDelegates,
supportedLocales: context.supportedLocales,
locale: context.locale,
home: MyHomePage()
);
}
}
I have the same issue, unfortunatly none of the above proposed changes worked out for me.
Same here.. None of the above proposed changes worked out for me.
The same issue, none of the above-suggested answers worked!
If anyone still having this issue for csv files remove the easy_localization_loader. from pubspec and create a new file
import 'dart:developer';
import 'package:csv/csv.dart';
import 'package:csv/csv_settings_autodetection.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart' show rootBundle;
class CsvAssetLoader extends AssetLoader {
CSVParser? csvParser;
@override
Future<Map<String, dynamic>> load(String path, Locale locale) async {
if (csvParser == null) {
log('easy localization loader: load csv file $path');
csvParser = CSVParser(await rootBundle.loadString(path));
} else {
log('easy localization loader: CSV parser already loaded, read cache');
}
return csvParser!.getLanguageMap(locale.toString());
}
}
class CSVParser {
final String fieldDelimiter;
final String strings;
final List<List<dynamic>> lines;
static final csvSettingsDetector =
FirstOccurrenceSettingsDetector(eols: ['\r\n', '\n']);
CSVParser(this.strings, {this.fieldDelimiter = ','})
: lines = CsvToListConverter(csvSettingsDetector: csvSettingsDetector)
.convert(strings, fieldDelimiter: fieldDelimiter);
List getLanguages() {
return lines.first.sublist(1, lines.first.length);
}
Map<String, dynamic> getLanguageMap(String localeName) {
final indexLocale = lines.first.indexOf(localeName);
var translations = <String, dynamic>{};
for (var i = 1; i < lines.length; i++) {
translations.addAll({lines[i][0]: lines[i][indexLocale]});
}
return translations;
}
}
got the same problem , need help 😞
same issue any solution ??
i solved problem by delete all file generated and execute flutter pub run easy_localization:generate --source-dir ./translations
flutter pub run easy_localization:generate flutter pub run easy_localization:generate --source-dir 'translations' --output-dir 'lib/generated' --output-file 'translations.g.dart' --format keys
I solved wrapping the MaterialApp's home with a Builder
return MaterialApp(
localizationsDelegates: context.localizationDelegates,
supportedLocales: context.supportedLocales,
locale: context.locale,
home: Builder(
builder: (context) {
return MyWidget();
},
),
);
I think the problem is related to the BuildContext passed in the build method that hasn't registered yet the localization delegates of the MaterialApp. In this way the Builder use a context child of the MaterialApp
holy moly.. I solved it by adding '/' at the end of assets/translations...
I am still having this issue. Did anybody found a solution?
I have added this line into EasyLocalization(after runApp) and everything worked :
startLocale: Locale.fromSubtags(languageCode: 'en'),
I think a lot of very different problems are merged in this issue. A lot of them will be solved by the solutions of @Caffo17 and @johnsargado. However, if someone still has this problem, please comment here and code, so maintainers can reproduce it.