easy_localization
easy_localization copied to clipboard
Load Localization Delegate will be called after rebuild page
Hi
I wanna change locale by the context.setLocale():
if(context.locale.languageCode == "en"){
debugPrint("en -----> fa");
await context.setLocale(const Locale("fa"));
}else if(context.locale.languageCode == "fa"){
debugPrint("fa -----> en");
await context.setLocale(const Locale("en"));
}
but I see the below log occurs:
[Easy Localization] [DEBUG] Load asset from assets/translations
[Easy Localization] [Info] Locale fa changed
[Easy Localization] [Info] Locale fa saved
[Easy Localization] [DEBUG] Build
[Easy Localization] [DEBUG] Init Localization Delegate
[Easy Localization] [DEBUG] Init provider
my_flutter_app_log ---> page build () method called **** here
[Easy Localization] [DEBUG] Load Localization Delegate **** and here
Is it true?
I think Load Localization Delegate have to be called before rebuilding my page.
Also, I see a strange behavior, so that some texts in my app are translated in reverse. for example:
The toolbar text is en when the app locale is changed to the fa and conversely the toolbar text is fa while the app locale is changed to en!
main.dart:
void main() async {
while (Platform.localeName.isEmpty) {
await Future.delayed(const Duration(microseconds: 300), () {});
}
WidgetsFlutterBinding.ensureInitialized();
await EasyLocalization.ensureInitialized();
runApp(EasyLocalization(
child: const ProviderScope(child: MyApp()),
supportedLocales: const [
Locale('en'),
Locale('fa'),
],
path: 'assets/translations', // I have 2 file fa.json & en.json in the assets/translations folder
fallbackLocale: const Locale('en'),
saveLocale: true,
useOnlyLangCode: true,
));
}
class MyApp extends ConsumerWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context, WidgetRef ref) {
return MaterialApp(
locale: context.locale,
supportedLocales: context.supportedLocales,
localizationsDelegates: context.localizationDelegates,
initialRoute: "/",
onGenerateRoute: RouteGenerator.generateRoute,
);
}
}
what is the problem?
no response?
I have experienced the same behavior. Some words are translated and others are switched direction without translating the words. But when I do hot reload or hot restart everything works correctly.

i have the same problem
any solutions?