- 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- Push new ARB keys to the Localization Service (optional)
A project admin generates an SDK API key in the Localization Service under Settings → SDK API key. It is shown once, so store it as a secret (for example a CI environment variable).
export CHILI_LOCALIZATION_API_KEY=<key>
dart run chili_localization:push --project <project id> --arb-dir resources/translations --dry-run
dart run chili_localization:push --project <project id> --arb-dir resources/translations- Only keys that do not exist in the project yet are added. Existing keys are never changed or deleted.
@key.descriptionbecomes the key's comment.- ARB files for languages the project does not support are skipped with a warning.
--dry-runprints the keys that would be added without writing anything.- Pushing does not publish a new translations version; publish from the Localization Service as before.
- 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