Easy Localization] [WARNING] Localization key [XXX] not found
error
@aissat

folder:

Pubspec.yaml

After ran below command, flutter pub run easy_localization:generate --source-dir ./assets/translations -f keys -o locale_keys.g.dart
easy localization: All done! File generated in /Users/###/Documents/projects/versionControl/###/###/lib/generated/locale_keys.g.dart
@aissat
====
main.dart

materialApp

@aissat hi chief, any update on this?
in pubspec.yaml you are refereeing to assets/translations
and in the EasyLocalization you are saying the json files are in assets/translators
please make sure the both are the same path
in
pubspec.yamlyou are refereeing toassets/translationsand in theEasyLocalizationyou are saying the json files are inassets/translatorsplease make sure the both are the same path
after changing also am getting same error :-(
@maxzod
I'm having similar error, half strings in localized json are working, half not.
Just to update, after performing hot reload, translations are applyed.
Have same issue. Translations work only after hot reload
Have the same issue. Even a hot restart doesn't help.
Have the same issue. Even a hot restart doesn't help.
yes for me too.. i did try many. didn't worked out!
I found the problem. In my case, the reason was that I didn't use delegate from context. My code was
localizationsDelegates:[
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate
],
And following helped me.
localizationsDelegates: context.localizationDelegates,
But it seems that @MuthuSubramaniam has a different problem
Same problem here.
got the same problem , any new ?
@MuthuSubramaniam , @YouSour Try to remove assetLoader: JsonAssetLoader(). It seems strange, but I saw that JsonAssetLoader was not using on example, even on comments, so I removed that and solved my problem.
Lemme have a try! thank you!
@crazyguysdev solved
same problem with version easy_localization: ^3.0.1
not work
print('title'.tr()');
Same issue here :(
~~This issue still exists. I am using easy_localization: ^3.0.1~~
My translations would also only start working after a "Hot Reload".
But I found that the root issue for me was that I was trying to use translations when instantiating the MaterialApp widget.
As soon as I moved the translations deeper in my widget tree, specifically inside the widget that was being assigned as my MaterialApp's home widget, the issue no longer occurred.
Small example of code with issue:
// EasyLocalization is the top-most widget but is not shown here
// You can consider it was already called previous to this code
Widget build(BuildContext context) {
return MaterialApp(
localizationsDelegates: context.localizationDelegates,
supportedLocales: context.supportedLocales,
locale: context.locale,
home: MyHomePage(title: LocaleKeys.title_homepage.tr()), <-- Issue here
);
}
All I had to do, was move LocaleKeys.title_homepage.tr() to be called inside the MyHomePage widget, and the error was handled.
Although this doesn't seem to be the same as the issue reported here, I hope it can be of help to some of you.
Could someone that still has this issue post his code here, or a minimal sample to reproduce? (inclunding his json files)
Duplicate of #394
import 'package:Majannah/History.dart'; import 'package:Majannah/phonenumber.dart'; import 'package:Majannah/playingmode.dart'; import 'package:Majannah/profile.dart'; import 'package:Majannah/saved.dart'; import 'package:Majannah/savedfilter.dart'; import 'package:Majannah/search.dart'; import 'package:Majannah/share.dart'; import 'package:Majannah/subschannels.dart'; import 'package:Majannah/top/topchannels.dart'; import 'package:Majannah/topepisodes.dart'; import 'package:Majannah/update_interests.dart'; import 'package:Majannah/updateprofile.dart'; import 'package:Majannah/verification.dart'; import 'package:Majannah/verifyphone.dart'; import 'package:get/get.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:get/get_navigation/get_navigation.dart'; import 'package:easy_localization/easy_localization.dart'; //import 'package:podcast/verification.dart';
import 'Channel_new.dart'; import 'Sign_up.dart'; import 'accountsetting.dart'; import 'arabic.dart'; import 'arabic2.dart'; import 'carplay.dart'; import 'change_password.dart'; import 'channel.dart'; import 'channelscreen.dart'; import 'contactus.dart'; import 'create_account.dart'; import 'culture.dart'; import 'deleteconfirmation.dart'; import 'downloads.dart'; import 'downloadsdelete.dart'; import 'explore.dart'; import 'forgot.dart'; import 'historyfilter.dart'; import 'home.dart'; import 'interests.dart'; import 'language.dart'; import 'library.dart'; import 'loading.dart'; import 'localization.dart'; import 'login.dart'; import 'login_page.dart'; import 'mult.dart'; import 'new_account.dart'; import 'notification.dart'; import 'nowplaying.dart';
//import 'forgot.dart'; //import 'login.dart'; //import 'login_page.dart'; void main() async { WidgetsFlutterBinding.ensureInitialized(); await EasyLocalization.ensureInitialized();
runApp(
EasyLocalization(
supportedLocales: [Locale('en', 'US'), Locale('ar', 'SA')],
path: 'assets/translations_1', // <-- 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: Home() ); } }
class Majannah extends StatefulWidget { const Majannah({super.key});
@override State<Majannah> createState() => _MajannahState(); }
class _MajannahState extends State<Majannah> { final LanguageController _languageController = Get.put(LanguageController());
// This widget is the root of your application. @override Widget build(BuildContext context) { return GetMaterialApp( debugShowCheckedModeBanner: false, title: 'Majannah', translations: MyTranslations(), locale: Locale(_languageController.selectedLanguage.value), fallbackLocale: Locale('en'),
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.black),
useMaterial3: true,
),
home: Home(),
);
} } class LanguageController extends GetxController { var selectedLanguage = 'en'.obs;
void changeLanguage(String languageCode) { selectedLanguage.value = languageCode; } }
what is error in this?
@saiprashadmurali1511 It is impossible to help you this way. I assume you have the "Localization key [xxx] not found"- warning.
If you want help, you need to create a sample which someone else can use to reproduce. This sample should....
- be possible to run without any dependency (getx in your case)
- be complete, so only main.dart content is needed to run
- not contain anything not relevant to this issue
Please keep in mind that this is open source an people help you in their free time without any cost, so you should put in the maximum effort to make it easy to help you.