ilteoood / flutter_i18n

I18n made easy, for Flutter!
MIT License
217 stars 57 forks source link

NetworkFileTranslationLoader fetches locale multiple times and ignores forcedLocale #216

Closed dani-filipovic closed 3 months ago

dani-filipovic commented 8 months ago

I am using the NetworkFileTranslationLoader with these settings:

localizationsDelegates: [ FlutterI18nDelegate( translationLoader: NetworkFileTranslationLoader( baseUri: Uri.https('...', '/app/strings'), useCountryCode: false, decodeStrategies: [ JsonDecodeStrategy(), ], forcedLocale: Locale(widget.selectedLanguage.isocode), ), ), GlobalMaterialLocalizations.delegate, GlobalWidgetsLocalizations.delegate ],

The main App widget receives a selectedLanguage as an argument and passes it to the forcedLocale argument. Even though the forcedLocale parameter is passed, the fallbackLocale is still being fetched.

There are a few issues here:

Since we have quite large translation files, this is adding more than 2 seconds of network traffic to our app immediately after opening it.

ilteoood commented 3 months ago

Hi @dani-filipovic, the double call you see related to fallback translations, used by default if an entry is not found in your main file to avoid leaving you with an untranslated key. I guess we can make the fallback an optional parameter, to avoid fetching it if not needed.

ilteoood commented 3 months ago

Fixed with version 0.36.2, you can set fallbackFile to null to avoid the double call