Skip to content

ChiliLabs/chili_localization

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Chili Localization SDK for Flutter

How to implement

  1. Add dependency to pubspec.yaml
  chili_localization:
    git:
      url: https://github.com/ChiliLabs/chili_localization.git
      ref: main
  1. 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,
      );
  });
}
  1. 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);
    },
);
  1. 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

How it works

  • When RemoteLocalizationClient.loadTranslations is 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 there is no new version, app will use local file if exists, otherwise local translations

About

Flutter SDK for Remote Localisation service

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages