Short answer
You write the strings in ARB files per language, and the gen-l10n tool generates an AppLocalizations class with typed functions for strings with parameters and plurals, then you register the delegates and supported locales in MaterialApp.
Explanation
Generation is enabled with flutter: generate: true and an l10n.yaml file. The template ARB file (app_en.arb) contains the strings, their descriptions, and their parameters, and the other files are copied with translations. ICU syntax supports plural and select, which matters in Arabic because it has multiple plural forms (zero/one/two/few/many/other). flutter_localizations handles translating Material components themselves, and the writing direction is set from the locale automatically. Avoid assembling sentences by string concatenation because word order differs between languages.
Code example
# pubspec.yaml
# flutter:
# generate: true
# dependencies:
# flutter_localizations: { sdk: flutter }
# intl: any
# l10n.yaml
arb-dir: lib/l10n
template-arb-file: app_en.arb
output-localization-file: app_localizations.dart
// lib/l10n/app_ar.arb
// {
// "@@locale": "ar",
// "greeting": "Hello {name}",
// "@greeting": { "placeholders": { "name": { "type": "String" } } },
// "itemCount": "{count, plural, =0{No items} =1{one item} =2{two items} few{{count} items} other{{count} items}}",
// "@itemCount": { "placeholders": { "count": { "type": "int" } } }
// }
// main.dart
MaterialApp(
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
home: const HomePage(),
);
// usage
Text(AppLocalizations.of(context)!.greeting('Mona'));
Text(AppLocalizations.of(context)!.itemCount(3));Common mistakes
- Building sentences by concatenating translated strings (such as 'Hello ' + name), which breaks word order in other languages; use ARB parameters.
- Forgetting Arabic plural rules (zero/one/two/few/many/other) and writing a single plural form.