easy_localization
easy_localization copied to clipboard
JSON files not updating in Flutter web due to browser cache
The browser caches json files because they are loaded without a ?v=x.x query string. This means that the cache needs to be emptied when a change is made which is highly problematic.
@jacksilver2 thanks, thanks for issue, if you have a solution you can do a PR, it will help the project 😉
Hey guys, I'm just looking for a new localization variant for my productive application and I'm struggling with exactly this behaviour.
After an update of my web app, including increasing the version number in the index.html file
<script src="main.dart.js?version=xxx" type="application/javascript"></script>
, the users have to empty their browser cache to load the changed .json translations.
Can easy_localization handle this behaviour better? Thanks!
Does someone has a solution?
Same problem. Does anyone have a workaround?
If you use easy_localization generate feature you don't have this issue anymore since your lang files are generated in your dart code
Generates the lang file : flutter pub run easy_localization:generate --source-dir ./assets/languages -O lib/languages
Generates the key file : flutter pub run easy_localization:generate --source-dir ./assets/languages -O lib/languages -o locale_keys.g.dart -f keys
Add assetLoader to your EasyLocalization config
void main(){
runApp(EasyLocalization(
child: MyApp(),
supportedLocales: [Locale('en', 'US'), Locale('ar', 'DZ')],
path: 'resources/langs',
assetLoader: CodegenLoader()
));
}
Add a translation in a widget : Text(LocaleKeys.title.tr())
@TheSmartMonkey thanks a lot for this input, will try this very soon and come back to this topic.