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

why startLocale not work? #699

Open
xiaopindev opened this issue Aug 1, 2024 · 1 comment
Open

why startLocale not work? #699

xiaopindev opened this issue Aug 1, 2024 · 1 comment

Comments

@xiaopindev
Copy link

Precondition

iOS info.plist

<key>CFBundleLocalizations</key>
<array>
<string>ar</string>
<string>de</string>
<string>en</string>
<string>es</string>
<string>fr</string>
<string>it</string>
<string>ja</string>
<string>ko</string>
<string>pt</string>
<string>zh-Hant</string>
</array>

Flutter project

MyProject
     languages/
           ar.json
           de.json
           en.json
           ...
           zh-Hant.json
           
     pubspec.yaml
          flutter:
             assets:
                 - languages/

Problem description

If the startLocale is Locale('zh', 'Hant'), it is always not work.

fallbackLocale: const Locale('en'),
startLocale: const Locale('zh', 'Hant'), 

If I set the fallbackLocale is Locale('zh', 'Hant'), The program loads the language pack normally after restarted.

fallbackLocale: const Locale('zh', 'Hant'),
startLocale: const Locale('zh', 'Hant'), 

Main code:

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await EasyLocalization.ensureInitialized();

  final global = Get.put(AppGlobal(), permanent: true);
  final savedLocale = await global.savedLocale();
  Logger.log('当前存储的语言 $savedLocale');
  runApp(
    EasyLocalization(
      supportedLocales: const [
        Locale('ar'),
        Locale('de'),
        Locale('en'),
        Locale('es'),
        Locale('fr'),
        Locale('it'),
        Locale('ja'),
        Locale('ko'),
        Locale('pt'),
        Locale('zh', 'Hant')
      ],
      path: 'languages',
      fallbackLocale: const Locale('en'),
      startLocale: const Locale('zh', 'Hant'), 
      child: const MyApp(),
    ),
  );
}

All other language packs load normally after restarting

Locale('ar'),
Locale('de'),
Locale('en'),
Locale('es'),
Locale('fr'),
Locale('it'),
Locale('ja'),
Locale('ko'),
Locale('pt'),
@xiaopindev
Copy link
Author

My temporary solution

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await EasyLocalization.ensureInitialized();
  await DatabaseHelper().initDatabase();

  final global = Get.put(AppGlobal(), permanent: true);
  final savedLocale = await global.savedLocale();
  Logger.log('当前存储的语言 $savedLocale');
  runApp(
    EasyLocalization(
      supportedLocales: const [
        Locale('ar'),
        Locale('de'),
        Locale('en'),
        Locale('es'),
        Locale('fr'),
        Locale('it'),
        Locale('ja'),
        Locale('ko'),
        Locale('pt'),
        Locale('zh', 'Hant')
      ],
      path: 'languages',
      fallbackLocale: savedLocale.languageCode == 'zh'
          ? const Locale('zh', 'Hant')
          : const Locale('en'),
      startLocale: savedLocale, 
      child: const MyApp(),
    ),
  );
}

Is this an Easy_localization bug? My solution is obviously not the best, waiting for your reply!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant