-
-
Notifications
You must be signed in to change notification settings - Fork 336
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
Localization key [key] not found after update to version 3.0.0 #349
Comments
I am also facing the same issue. |
I am also facing the same issue |
same issue here |
@Supercaly @bruntzcreative @osmaneser @SebastianKumor can you show code example for reprodyce this bug? |
@Overman775 Hi. Thank you. I hope explain to for you. I wrote custom textWidget. i am using that. for example using this way like 78. line. then as in the picture below using string extension named locale. i called custom text widget that. |
@osmaneser Flutter web? |
I am facing the same issue in Flutter for Android too, |
No, mobile |
|
Hi, same issue here on multiple apps targeting android. |
@PiotrFLEURY @osmaneser @Supercaly @bruntzcreative @SebastianKumor please sent your MaterialApp/CupertinoApp widget. And will be helpful see example project with this bug. |
This is my full widget that is run with class AppWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return EasyLocalization(
supportedLocales: [
Locale('en'),
Locale('it'),
],
path: "assets/translations",
assetLoader: CodegenLoader(),
fallbackLocale: Locale('en'),
child: BlocProvider<AuthBloc>(
create: (context) =>
AuthBloc(repository: locator<AuthRepository>())..checkAuth(),
child: ServiceManager(
notificationService: locator<NotificationService>(),
linkService: locator<LinkService>(),
child: MaterialApp(
title: "Tasky App",
theme: lightTheme,
darkTheme: darkTheme,
navigatorKey: locator<NavigationService>().navigationKey,
onGenerateRoute: Routes.onGenerateRoute,
initialRoute: Routes.splash,
),
),
),
);
}
} In my case, the problem happens with both Android and Web platforms, but only if I use the package at version 3.0.0. For example version |
same here. Works great with |
@Overman775 this is my version. I have not tried the previous version and I am also running on
|
I've created a test app to experiment more on the problem. This is my import 'package:flutter/material.dart';
import 'package:easy_localization/easy_localization.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await EasyLocalization.ensureInitialized();
runApp(EasyLocalization(
supportedLocales: [Locale("en")],
path: "assets",
fallbackLocale: Locale("en"),
child: MyApp(),
));
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
supportedLocales: context.supportedLocales,
locale: context.locale,
localizationsDelegates: context.localizationDelegates,
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'title'.tr()),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text('msg').tr(),
Text(
'$_counter',
style: Theme.of(context).textTheme.headline4,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'increment'.tr(),
child: Icon(Icons.add),
),
);
}
} this is my name: test_localization_bug
description: A new Flutter application.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 1.0.0+1
environment:
sdk: ">=2.7.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.2
easy_localization: ^3.0.0
dev_dependencies:
flutter_test:
sdk: flutter
flutter:
uses-material-design: true
assets:
- assets/en.json and this is my {
"title": "Flutter Demo Home Page",
"msg": "You have pushed the button this many times:",
"increment": "Increment"
} Note the fact that I'm using SDK 2.7.0, I've tried 2.12.0-0 but the problem is the same. When I launch the app the Performing hot restart...
Waiting for connection from debug service on Chrome...
Restarted application in 291ms.
[🌎 Easy Localization] [DEBUG] Localization initialized
[🌎 Easy Localization] [DEBUG] Start
[🌎 Easy Localization] [DEBUG] Init state
[🌎 Easy Localization] [DEBUG] Build
[🌎 Easy Localization] [DEBUG] Init Localization Delegate
[🌎 Easy Localization] [DEBUG] Init provider
[🌎 Easy Localization] [WARNING] Localization key [title] not found
[🌎 Easy Localization] [DEBUG] Load Localization Delegate
[🌎 Easy Localization] [DEBUG] Load asset from assets
[🌎 Easy Localization] [DEBUG] Build
[🌎 Easy Localization] [DEBUG] Init Localization Delegate
[🌎 Easy Localization] [DEBUG] Init provider
[🌎 Easy Localization] [DEBUG] Build
[🌎 Easy Localization] [DEBUG] Init Localization Delegate
[🌎 Easy Localization] [DEBUG] Init provider I think this is a problem with the logic that loads the translations since at first, it doesn't work, but then it does. I've tried cloning the easy_location project and run the example app, but there the problem seems not to be present. |
I experienced this with the previous version. It could be related to this issue although hot restart does not rectify the problem. |
@bruntzcreative @Supercaly this old "bug". Problen in localization delegates in [🌎 Easy Localization] [WARNING] Localization key [title] not found |
@Overman775
|
@SebastianKumor |
@Overman775 Yes its Web, and can you explain what do you mean by level context? Is it related to the folder structure of the project ? I am new to flutter |
@SebastianKumor refactoring(split) Scaffold to extrenal widget, like Home() widget etc. same issue #355 |
Thanks @Overman775 . Put the home widget in a different file seems to fix the problem. Plus, I didn't noticed the mandatory parameters for MaterialApp (works without those parameters before the 3.0.0) : localizationsDelegates: context.localizationDelegates,
supportedLocales: context.supportedLocales,
locale: context.locale, It could be great tu put it in bold or something for the ones who migrates. The code below works : // main.dart
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await EasyLocalization.ensureInitialized();
runApp(
EasyLocalization(
child: MyApp(),
supportedLocales: [
Locale('en'),
Locale('fr'),
],
path: 'assets/translations',
fallbackLocale: Locale('en'),
useFallbackTranslations: true,
),
);
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
localizationsDelegates: context.localizationDelegates,
supportedLocales: context.supportedLocales,
locale: context.locale,
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Home('Flutter Demo Home Page'),
);
}
} // home.dart
class Home extends StatelessWidget {
final String title;
Home(this.title);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
SvgPicture.asset('assets/images/iceberg.svg'),
Text(
'hello_world'.tr(),
),
],
),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
} Not a big deal to make a new file Hope this will help |
Ok, some update on my problem. MaterialApp(
supportedLocales: context.supportedLocales,
locale: context.locale,
localizationsDelegates: context.localizationDelegates,
//...
), Adding this, with the The following JSNoSuchMethodError was thrown building MediaQuery(MediaQueryData(size: Size(575.0, 619.0), devicePixelRatio: 1.0, textScaleFactor: 1.0, platformBrightness: Brightness.light, padding: EdgeInsets.zero, viewPadding: EdgeInsets.zero, viewInsets: EdgeInsets.zero, alwaysUse24HourFormat: false, accessibleNavigation: false, highContrast: false, disableAnimations: false, invertColors: false, boldText: false, navigationMode: traditional)):
TypeError: Cannot read property 'then' of undefined
The relevant error-causing widget was:
MaterialApp file:///C:/Users/Lorenzo/Desktop/taskyapp/lib/presentation/app_widget.dart:35:24
When the exception was thrown, this was the stack:
packages/flutter/src/widgets/localizations.dart 57:51 _loadAll
packages/flutter/src/widgets/localizations.dart 533:8 load
packages/flutter/src/widgets/localizations.dart 497:5 initState
packages/flutter/src/widgets/framework.dart 4632:57 [_firstBuild]
packages/flutter/src/widgets/framework.dart 4469:5 mount
...
==================================================================================================== ======== Exception caught by widgets library =======================================================
The following UnsupportedError was thrown building MediaQuery(MediaQueryData(size: Size(575.0, 619.0), devicePixelRatio: 1.0, textScaleFactor: 1.0, platformBrightness: Brightness.light, padding: EdgeInsets.zero, viewPadding: EdgeInsets.zero, viewInsets: EdgeInsets.zero, alwaysUse24HourFormat: false, accessibleNavigation: false, highContrast: false, disableAnimations: false, invertColors: false, boldText: false, navigationMode: traditional)):
Unsupported operation: Cannot modify unmodifiable map
The relevant error-causing widget was:
MaterialApp file:///C:/Users/Lorenzo/Desktop/taskyapp/lib/presentation/app_widget.dart:35:24
When the exception was thrown, this was the stack:
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 236:49 throw_
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/private/linked_hash_map.dart 265:5 _set
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 324:14 _checkAndCall
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 388:10 callMethod
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 392:5 dsend
...
==================================================================================================== If I remove the three lines from MaterialApp those errors disappears, but then the missing key error comes back |
Ok, I think I found the cause of the problem! Here a recap for all the people that were having the same issue:
supportedLocales: context.supportedLocales,
locale: context.locale,
localizationsDelegates: context.localizationDelegates,
It turned out that point 2 was causing the strange errors of my previous comment, removing it fixed everything. So for the moment, I close this issue, reopen it if the two points above don't help you. |
I fixed the problem in my main.dart file going from this:
To this:
plus a stateless widget:
|
Hi I'm switching my app to null safety so I've imported version 3.0.0 of this package, but when I run my app or my unit test I get this message on the log:
For context I'm using the
CodegenLoader
asset loader andText('email_label').tr()
in WidgetsThis is my main:
The text was updated successfully, but these errors were encountered: