Easy_localization: IOS App didn't get device locale for first launch

Created on 22 May 2020  路  5Comments  路  Source: aissat/easy_localization

Hi, I've a little issue, I don't know if i missed some configuration.
I use version 2.3.2.
My app support 2 languages, fr and ar.
on Android it works as expected but on IOS the first launch app didn't get device locale but when restart app it load with device locale.
I've added this to info.plist but nothing happens

<key>CFBundleLocalizations</key>
<array>
    <string>fr</string>
    <string>ar</string>
</array>

My code is:

void main(){
  runApp(EasyLocalization(
    child: MyApp(),
    saveLocale: false,
    supportedLocales: [
      Locale('fr', 'FR'),
      Locale('ar', 'US'),
    ],
    path: 'assets/langs',
//    fallbackLocale: Locale('fr', 'FR'),
    useOnlyLangCode: true,
  ));
}

...
child: MaterialApp(
        title: Variables.appName,
        localizationsDelegates: EasyLocalization.of(context).delegate,
        supportedLocales: context.supportedLocales,
        locale: context.locale,
        theme: ThemeData(
           primaryColor: Variables.primaryColor,
           textTheme:GoogleFonts.sourceSansProTextTheme(textTheme).copyWith(
             bodyText2: GoogleFonts.montserrat(textStyle: textTheme.bodyText2),
           ),
           backgroundColor: Colors.white
        ),
        debugShowCheckedModeBanner: false,
        home: CheckAuth(),
      ),
...
waiting for customer response

Most helpful comment

void main() async {
   while(Platform.localeName == null){
    await Future.delayed(const Duration(microseconds: 300), (){});
  }
  runApp(EasyLocalization(
    child: MyApp(),
    saveLocale: false,
    supportedLocales: [
      Locale('fr', 'FR'),
      Locale('ar'),
    ],
    path: 'assets/langs',
    fallbackLocale: Locale('fr', 'FR'),
    useOnlyLangCode: true,
  ));
}

All 5 comments

@BechirAhmed same bug #141 ?

i write issue to Flutter team https://github.com/flutter/flutter/issues/55642

Thank you for the informations, I got the same issue ! :-)

Okay, thanks @Overman775.
About the workaround you create, i've tried it like below but seems not working, i'm not sure is this the right way to apply it

import 'dart:io';
import 'package:intl/intl_standalone.dart';

Future<Locale> _getDeviceLocale() async {
  while(Platform.localeName == null){
    await Future.delayed(const Duration(microseconds: 300), (){});
  }
  final _deviceLocale = await findSystemLocale();
  log('easy localization: Device locale $_deviceLocale');
  return localeFromString(_deviceLocale);
}

void main(){
  _getDeviceLocale();
  runApp(EasyLocalization(
    child: MyApp(),
    saveLocale: false,
    supportedLocales: [
      Locale('fr', 'FR'),
      Locale('ar'),
    ],
    path: 'assets/langs',
    fallbackLocale: Locale('fr', 'FR'),
    useOnlyLangCode: true,
  ));
}

Still the same bug, it log device locale only on second launch

void main() async {
   while(Platform.localeName == null){
    await Future.delayed(const Duration(microseconds: 300), (){});
  }
  runApp(EasyLocalization(
    child: MyApp(),
    saveLocale: false,
    supportedLocales: [
      Locale('fr', 'FR'),
      Locale('ar'),
    ],
    path: 'assets/langs',
    fallbackLocale: Locale('fr', 'FR'),
    useOnlyLangCode: true,
  ));
}

Supeeer, Thanks

Was this page helpful?
0 / 5 - 0 ratings

Related issues

EmmanuelMess picture EmmanuelMess  路  7Comments

KarlChow92 picture KarlChow92  路  3Comments

Jerrywyx picture Jerrywyx  路  4Comments

fatimahossny picture fatimahossny  路  4Comments

HugoHeneault picture HugoHeneault  路  3Comments