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

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

Closed
MuthuSubramaniam opened this issue Aug 28, 2021 · 20 comments
Closed
Labels
duplicate This issue or pull request already exists waiting for customer response Waiting for customer response

Comments

@MuthuSubramaniam
Copy link

MuthuSubramaniam commented Aug 28, 2021

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
Copy link
Author

@aissat hi chief, any update on this?

@maxzod
Copy link

maxzod commented Sep 1, 2021

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

@MuthuSubramaniam
Copy link
Author

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

@ibarisic05
Copy link

ibarisic05 commented Sep 2, 2021

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

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

@VictorYezhov
Copy link

Have same issue. Translations work only after hot reload

@shushper
Copy link

shushper commented Sep 9, 2021

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

@MuthuSubramaniam
Copy link
Author

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

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

@shushper
Copy link

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

@mikenussbaumer
Copy link

Same problem here.

@YouSour
Copy link

YouSour commented Nov 24, 2021

got the same problem , any new ?

@crazyguysdev
Copy link

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

@MuthuSubramaniam
Copy link
Author

Lemme have a try! thank you!

@YouSour
Copy link

YouSour commented Jan 5, 2022

@crazyguysdev solved

@abdalazeez1
Copy link

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

@Shyamranny
Copy link

Same issue here :(

@FabioSa222
Copy link

FabioSa222 commented May 7, 2023

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.

@bw-flagship
Copy link
Collaborator

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

@bw-flagship bw-flagship added the waiting for customer response Waiting for customer response label May 14, 2023
@aissat aissat added the duplicate This issue or pull request already exists label Sep 10, 2023
@aissat
Copy link
Owner

aissat commented Sep 10, 2023

Duplicate of #394

@aissat aissat marked this as a duplicate of #394 Sep 10, 2023
@aissat aissat closed this as completed Sep 10, 2023
@aissat aissat linked a pull request Sep 10, 2023 that will close this issue
3 tasks
@aissat aissat removed a link to a pull request Sep 10, 2023
3 tasks
@saiprashadmurali1511
Copy link

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 createState() => _MajannahState();
}

class _MajannahState extends State {
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?

@bw-flagship
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists waiting for customer response Waiting for customer response
Projects
None yet
Development

No branches or pull requests