easy_localization icon indicating copy to clipboard operation
easy_localization copied to clipboard

Easy Localization] [WARNING] Localization key [XXX] not found

Open MuthuSubramaniam opened this issue 4 years ago • 14 comments

error

@aissat

image

folder:

image

Pubspec.yaml image

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

image

materialApp

image

MuthuSubramaniam avatar Aug 28 '21 07:08 MuthuSubramaniam

@aissat hi chief, any update on this?

MuthuSubramaniam avatar Aug 30 '21 05:08 MuthuSubramaniam

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

maxzod avatar Sep 01 '21 10:09 maxzod

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

after changing also am getting same error :-(

@maxzod

MuthuSubramaniam avatar Sep 02 '21 01:09 MuthuSubramaniam

I'm having similar error, half strings in localized json are working, half not.

Just to update, after performing hot reload, translations are applyed.

ibarisic05 avatar Sep 02 '21 07:09 ibarisic05

Have same issue. Translations work only after hot reload

VictorYezhov avatar Sep 07 '21 16:09 VictorYezhov

Have the same issue. Even a hot restart doesn't help.

shushper avatar Sep 09 '21 16:09 shushper

Have the same issue. Even a hot restart doesn't help.

yes for me too.. i did try many. didn't worked out!

MuthuSubramaniam avatar Sep 10 '21 01:09 MuthuSubramaniam

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

shushper avatar Sep 15 '21 10:09 shushper

Same problem here.

mikenussbaumer avatar Nov 07 '21 15:11 mikenussbaumer

got the same problem , any new ?

YouSour avatar Nov 24 '21 04:11 YouSour

@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.

crazyguysdev avatar Jan 04 '22 16:01 crazyguysdev

Lemme have a try! thank you!

MuthuSubramaniam avatar Jan 05 '22 00:01 MuthuSubramaniam

@crazyguysdev solved

YouSour avatar Jan 05 '22 03:01 YouSour

same problem with version easy_localization: ^3.0.1 not work
print('title'.tr()');

abdalazeez1 avatar Jun 15 '22 09:06 abdalazeez1

Same issue here :(

Shyamranny avatar Apr 13 '23 02:04 Shyamranny

~~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.

FabioSa222 avatar May 07 '23 19:05 FabioSa222

Could someone that still has this issue post his code here, or a minimal sample to reproduce? (inclunding his json files)

bw-flagship avatar May 14 '23 11:05 bw-flagship

Duplicate of #394

aissat avatar Sep 10 '23 23:09 aissat

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 avatar Oct 31 '23 10:10 saiprashadmurali1511

@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.

bw-flagship avatar Nov 02 '23 14:11 bw-flagship