services
Localization

Localization Service

By default Aurora comes with internationalization support. This service is responsible for providing the localization service to the app. This service is using the riverpod package for state management.

Here I am using the intl package for localization. This package is used to generate the localization files from the arb files.

├── localization
│   ├── arb
│   │   ├── app_bn.arb
│   │   └── app_en.arb
│   ├── extention
│   │   └── locale_extention.dart
│   └── providers
│       ├── localization_provider.dart
│       └── localization_provider.g.dart
|-- l10n.yaml

Localization yaml

Flutter need a l10n.yaml file to generate the localization files. This file is responsible for generating the localization files from the arb files.

l10n.yaml
arb-dir: lib/services/localization/arb
template-arb-file: app_en.arb
output-localization-file: app_localizations.dart
nullable-getter: false

Arb

By default Aurora supports two languages English and Bangla. You can add more languages by adding the arb files in the arb folder.

In this folder I am adding the arb files. This folder contains the arb files. This files are used to generate the localization files. This folder refence to the l10n.yaml file.

services/localization/arb/app_bn.arb
{
  "appTitle": "ফ্লাটার অরোরা",
}

Extention

Here I am adding the locale_extention.dart file. This file is used to add the l10n extention to the BuildContext. This extention is used to get the localization files from the BuildContext.

services/localization/extention/locale_extention.dart
import 'package:flutter/widgets.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
 
extension LocalizedBuildContext on BuildContext {
  AppLocalizations get l10n => AppLocalizations.of(this);
}

Providers

Here I am adding the localization_provider.dart file. This file is used to provide the localization service to the app. This file is using the riverpod package for state management.

services/localization/providers/localization_provider.dart
part 'localization_provider.g.dart';
 
@riverpod
Locale? appLocalizationService(AppLocalizationServiceRef ref) {
  final appSettings = ref.watch(appSettingsProvider);
 
  final k =
      appSettings.whenData((value) => AppLocales.getLocale(value.language));
 
  return k.value;
}

This file has a part file. This file is generated by the flutter pub run build_runner build command. This file is used to provide the localization service to the app.

services/localization/providers/localization_provider.g.dart
// GENERATED CODE - DO NOT MODIFY BY HAND