- Add dependency to pubspec.yaml
chili_localization:
git:
url: https://github.com/ChiliLabs/chili_localization.git
ref: main
- main.dart -> add these lines in bootstrap
void main() async {
await bootstrap(() async {
await configureDependencies();
RemoteLocalizationClient.init(remoteTranslationsUrl: EnvConfig.localizationUrl);
return App.withBloc(
enableDebugView: EnvConfig.enableDebugView,
);
});
}- Somewhere in app_bloc on app launch call this
final currentTranslationsVersion = await _statsRepository.localTranslationsVersion ?? 0;
final remoteTranslationsVersion = await _remoteConfigRepository.remoteTranslationsVersion;
await RemoteLocalizationClient.loadTranslations(
currentVersion: currentTranslationsVersion,
remoteVersion: remoteTranslationsVersion,
onAppliedNewVersion: (newVersion) async {
await _statsRepository.setRemoteTranslationsVersion(newVersion);
},
);- In you run_clean.sh scrip add this line at the end. First argument is input of the arb file, second argument is output dart file
flutter pub run chili_localization:gen resources/translations/app_en.arb lib/generated/translations/remote_fallback_localization.dart- When
RemoteLocalizationClient.loadTranslationsis called it checks if there is a new version of translations on the server with provided versions - If new version is available, app fetches the translations from the server and saves them to local storage file
- If failed to download, local file with translations will be used
- If local file does not exists, local translations will be used
- If failed to download, local file with translations will be used
- If there is no new version, app will use local file if exists, otherwise local translations