Easy_localization: Unconsistent _osLocale

Created on 13 Apr 2020  路  25Comments  路  Source: aissat/easy_localization

This bug isn't easy reproducible in debug, only in release mode and I don't know how to fix it.

Edit: We found a way to reproduce it, here and there is an open issue on flutter repo.
There also is a workaround providen by @Overman775

On first launch, it starts in french (fr_FR) on a french iPhone (SE or 6).
On second launch, it starts in english (en_US)

Then it randomly starts in french or english depending on some unknown dark magic...

I added required keys in Info.plist:

<key>CFBundleLocalizations</key>
<array>
    <string>fr</string>
    <string>en</string>
    <string>ca</string>
    <string>de</string>
    <string>es</string>
    <string>eu</string>
    <string>it</string>
    <string>nl</string>
    <string>zh</string>
</array>

And also

<key>CFBundleDevelopmentRegion</key>
<string>fr</string>

<key>CFBundleAllowMixedLocalizations</key>
<true/>

I ran flutter clean.

When I run flutter run ios it works nicely but when I deploy it to testflight it doesn't.

Here are the logs I gathered with the console:

1st launch:

14:49:44.220356+0200    Runner  flutter: EasyLocalization
14:49:44.221033+0200    Runner  flutter: initState
14:49:44.224536+0200    Runner  flutter: easy localization: Build
14:49:44.224589+0200    Runner  flutter: easy localization: Device locale fr_FR
14:49:44.224626+0200    Runner  flutter: _osLocale fr_FR
14:49:44.224682+0200    Runner  flutter: _checkInitLocale locale: fr _osLocale: fr
14:49:44.224719+0200    Runner  flutter: localePath assets/langs/st/fr.json

2nd launch:

14:50:04.279576+0200    Runner  flutter: EasyLocalization
14:50:04.290749+0200    Runner  flutter: initState
14:50:04.291415+0200    Runner  flutter: easy localization: Build
14:50:04.293339+0200    Runner  flutter: easy localization: Device locale en_US
14:50:04.293450+0200    Runner  flutter: _osLocale en_US
14:50:04.293597+0200    Runner  flutter: _checkInitLocale locale: fr _osLocale: en
14:50:04.293724+0200    Runner  flutter: _checkInitLocale locale: en _osLocale: en
14:50:04.293760+0200    Runner  flutter: localePath assets/langs/st/en.json
````

Here is my setup: 


```dart
final String assetsLocalePath = 'assets/langs/st/';
final List<String> supportedLocales = [
  'fr',
  'en',
  'ca',
  'de',
  'es',
  'eu',
  'it',
  'nl',
  'zh',
];

runApp(EasyLocalization(
      path: assetsLocalePath,
      useOnlyLangCode: true,
      child: MyApp(),
      saveLocale: false,
      supportedLocales:
          supportedLocales.map((locale) => Locale(locale)).toList(),
    ));

What shall I do?
Thanks a lot!

bug

Most helpful comment

@aissat @HugoHeneault find, problem in io.Platform.localeName... i thin its Flutter/Dart bug

hack:

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);
  }

All 25 comments

@aissat I already did it 馃

image

image

@aissat I just figured out that on the comments you gave me every locale has some files localized. What files should it be? 馃

@Overman775 plz check this

@HugoHeneault version 2.1.0+1?

I was on 2.1.0+0, I can try with 2.1.0+2 if you think it might change (but I can't see what changed though)

Thanks for your help! 馃憤

@HugoHeneault yep, try latest 2.1.0+2

I'm on it! Will come back to you later.

The AssetLoader api changed so I need to update my custom asset loader. Might be worth it to update more than the the +0 to +2 for next times, so we know changes are required :)

So I tried multiple builds:

  • I updated to latest 2.1.0+2: fr on 1st load the english on 2nd one
  • I re-created all the localizations with the screenboards/main files localizations: fr on 1st load the english on 2nd one
  • I removed locale: EasyLocalization.of(context).locale, from my MaterialApp: fr on 1st load the english on 2nd one

I'm running out of idea. Do you want me to provide you the builds so you can check it?

@HugoHeneault I don鈥檛 know what the problem is, maybe device bug

Try run example on your iPhone, don't forgeret add lang in xcode and json

Tried on 2 different devices. Same behavior.

The main problem is we only have this issue on release versions (coming from testflight).
I am on Flutter beta (Flutter 1.17.0). Maybe the issue is here?

Looking on my project.pbxproj file, there is only "en" in knownRegions. Would it has something to do?

@Overman775 I tested the example app on my iPhone, I reproduce the error! Would you help me? :)

Why is there no CFBundleLocalizations prop in Info.plist? Isn't this one of the step described in https://github.com/aissat/easy_localization/issues/130#issuecomment-609914572?

Here are the logs from my device:

I ran it in debug mode from AndroidStudio.

# 1st launch
10:54:05.819279+0200    Runner  flutter: EasyLocalization
10:54:05.990355+0200    Runner  flutter: initState
10:54:06.033618+0200    Runner  flutter: easy localization: Build
10:54:06.105304+0200    Runner  flutter: easy localization: Device locale fr_FR
10:54:06.115535+0200    Runner  flutter: easy localization: Load asset from resources/langs/fr-FR.json
10:54:06.137430+0200    Runner  flutter: easy localization: Init Localization Delegate
10:54:06.142128+0200    Runner  flutter: easy localization: Init provider
10:54:06.427504+0200    Runner  flutter: easy localization: Load Localization Delegate
10:54:38.840852+0200    Runner  HTHangEventCreate: HangTracing is disabled. Not creating a new event.
10:54:40.713897+0200    Runner  Can't end BackgroundTask: no background task exists with identifier 2 (0x2), or it may have already been ended. Break in UIApplicationEndBackgroundTaskError() to debug.
10:54:40.721025+0200    backboardd  Connection removed: IOHIDEventSystemConnection uuid:CAD0E92E-C6D3-4603-A7CB-BA2075065DFE pid:432 process:Runner type:Passive entitlements:0x0 caller:BackBoardServices: <redacted> + 380 attributes:{
HighFrequency = 0;
bundleID = "xx.xx.xx";
pid = 432;
} inactive:0 events:0 mask:0x0
10:54:40.724004+0200    mDNSResponder   [R812] DNSServiceRegister(<private>, 63132) STOP PID[432](Runner)
10:54:42.310300+0200    kernel  memorystatus: set assertion priority(10) target Runner:434
10:54:42.339107+0200    backboardd  Connection added: IOHIDEventSystemConnection uuid:E5244C1A-996C-4860-8768-76D7C9968EFA pid:434 process:Runner type:Passive entitlements:0x0 caller:BackBoardServices: <redacted> + 380 attributes:{
HighFrequency = 0;
bundleID = "xx.xx.xx";
pid = 434;
} inactive:1 events:0 mask:0x0

# 2nd launch

10:54:42.349437+0200    Runner  Initializing connection
10:54:42.349477+0200    Runner  Removing all cached process handles
10:54:42.352926+0200    Runner  FBSWorkspace connecting to endpoint : <private>
10:54:42.353003+0200    Runner  FBSWorkspace registering source: <private>
10:54:42.353091+0200    Runner  FBSWorkspace connected to endpoint : <private>
10:54:42.353166+0200    Runner  Added observer for process assertions expiration warning: <_RBSExpirationWarningAssertion: 0x283457640; identifier: com.apple.runningboardservices.processExpirationWarningForHandle; reason: observation; valid: YES>
10:54:42.356697+0200    Runner  Retrieving resting unlock: 0
10:54:42.358364+0200    Runner  Registering for test daemon availability notify post.
10:54:42.359669+0200    Runner  notify_get_state check indicated test daemon not ready.
10:54:42.359756+0200    Runner  Sending handshake request attempt #1 to server
10:54:42.359843+0200    Runner  Creating connection to com.apple.runningboard
10:54:42.382680+0200    Runner  Handshake succeeded
10:54:42.382818+0200    Runner  Identity resolved as application<fr.outdoorlab.st>
10:54:42.648214+0200    Runner  flutter: Observatory listening on http://127.0.0.1:58100/yZWT1eU1_2I=/
10:54:42.770178+0200    Runner  flutter: EasyLocalization
10:54:42.916647+0200    Runner  flutter: initState
10:54:42.931899+0200    Runner  flutter: easy localization: Build
10:54:43.005378+0200    mDNSResponder   [R813] DNSServiceRegister(4, 0, "<private>", "<private>", "<private>", "<private>", 58100) START PID[434](Runner)
10:54:43.006074+0200    Runner  FBSWorkspace already connected to endpoint : <private>
10:54:43.008183+0200    Runner  HTHangEventCreate: HangTracing is disabled. Not creating a new event.
10:54:43.064269+0200    Runner  flutter: easy localization: Device locale en_US
10:54:43.072402+0200    Runner  flutter: easy localization: Load asset from resources/langs/en-US.json
10:54:43.119539+0200    Runner  flutter: easy localization: Init Localization Delegate
10:54:43.123058+0200    Runner  flutter: easy localization: Init provider
10:54:43.357212+0200    Runner  flutter: easy localization: Load Localization Delegate

As you can see, on 2nd launch, Device locale en_US 馃

Here are my iPhone details:

IMG_B99777F16922-1
IMG_30773D1259FB-1

@HugoHeneault bug confirm.

@aissat reproduce: clean instal/debug on iOS emulator --> close(don't change lang) --> get off from memory iOS --> run again. Tested on stable & beta flutter channels. Android witout bug.

@Overman775 Cool. My setup is OK then. Hope you'll find the issue as I've been looking on it for quite awhile and have no idea on what's wrong.

@aissat If I can be of any help don't mind asking me!

Thanks a lot

@aissat @HugoHeneault find, problem in io.Platform.localeName... i thin its Flutter/Dart bug

hack:

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);
  }

@Overman775 Awesome! I'm gonna try your workaround! Is it ok if I add it before my runApp call?

On your flutter bug repo there is no CFBundleLocalizations key in the Info.plist? Is it on purpose?

Thanks!

@Overman775 Awesome! I'm gonna try your workaround! Is it ok if I add it before my runApp call?

Yep

@Overman775 Your workaround seems to work! 馃帀

Thanks a lot for your time and your help!
I'm deploying to testflight 馃

As it's really the end of a long and tiring debugging we're thinking of a (small) recurring support of your project to thank you for your nice work! 馃嵒

How doest it work as you're at least 2 collaborators working on it? :)

@HugoHeneault Glad that helped you 馃槂. Let's hope the Flutter/Dart team fixes it in Flutter

  1. fork repository
  2. work with develop branch
  3. pull reqwest to this repository develop branch
  4. work with code review
  5. we merge master branch

@Overman775 I was thinking about financial support, as we don't have much time to invest in working on this repo. :)

@HugoHeneault Thanks 馃槂

Fixed in 1.20.2 stable branch

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Overman775 picture Overman775  路  6Comments

Xgamefactory picture Xgamefactory  路  4Comments

gjrjf picture gjrjf  路  4Comments

necipk picture necipk  路  5Comments

LugonjaAleksandar picture LugonjaAleksandar  路  5Comments