How to implement Localization in Flutter Using l10n, a11y & i18n
Published in
1 min readDec 16, 2023
Creating project
flutter create -e --org com.example localization
Add Lang Commands
flutter pub add flutter_localizations --sdk=flutter
flutter pub add intl:any
Change in main.dart
import 'package:flutter_localizations/flutter_localizations.dart';
Change MaterialApp Class
return const MaterialApp(
...
// Localizations
locale: const Locale('gu'),
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
...
);
Creating a l10n.yaml
arb-dir: lib/l10n
template-arb-file: app_en.arb
output-localization-file: app_localizations.dart
# Other config...
synthetic-package: false
output-dir: lib/l10n
# use-escaping: true
# nullable-getter: false
Change a pubspec.yaml
flutter:
generate: true
Creating a Folder /lib/l10n and file app_en.arb
{
"home": "Home"
}
Creating a Hindi file app_hi.arb
{
"home": "होमे"
}
Creating a Gujarati file app_gu.arb
{
"home": "હોમે"
}
Folder Structure is
|-- lib
| |-- l10n
| |-- app_en.arb
| |-- app_hi.arb
| |-- app_gu.arb
| |-- main.dart
According to Apple Policy trans add in ios/Runner/Info.plist
<key>CFBundleLocalizations</key>
<array>
<string>en</string>
<string>hi</string>
<string>gu</string>
</array>
Please Read Apple Policy For
add
Text(AppLocalizations.of(context)!.home)