flutter-arb-localization
Flutter ARB Localization
Complete guide to localizing Flutter apps with LocEngine
Overview
Flutter uses ARB (Application Resource Bundle) files for localization, working with the intl package. LocEngine provides full support for Flutter projects, including automatic generation of localization delegates and support for pluralization, gender, and select cases.
ARB File Structure
// app_en.arb (English)
{
"@@locale": "en",
"appTitle": "My Flutter App",
"welcomeMessage": "Welcome to our app!",
"buttonSave": "Save",
"buttonCancel": "Cancel",
"itemsCount": "{count, plural, =1{1 item} other{{count} items}}",
"@@itemsCount": {
"description": "Number of items in cart"
}
}
{
"@@locale": "en",
"appTitle": "My Flutter App",
"welcomeMessage": "Welcome to our app!",
"buttonSave": "Save",
"buttonCancel": "Cancel",
"itemsCount": "{count, plural, =1{1 item} other{{count} items}}",
"@@itemsCount": {
"description": "Number of items in cart"
}
}
Multiple Languages
// app_de.arb (German)
{
"@@locale": "de",
"appTitle": "Meine Flutter App",
"welcomeMessage": "Willkommen in unserer App!",
"buttonSave": "Speichern",
"buttonCancel": "Abbrechen",
"itemsCount": "{count, plural, =1{1 Element} other{{count} Elemente}}",
}
{
"@@locale": "de",
"appTitle": "Meine Flutter App",
"welcomeMessage": "Willkommen in unserer App!",
"buttonSave": "Speichern",
"buttonCancel": "Abbrechen",
"itemsCount": "{count, plural, =1{1 Element} other{{count} Elemente}}",
}
Generated Dart Code
LocEngine automatically generates the localization delegate:
class AppLocalizations {
static Future<AppLocalizations> load(Locale locale) async {
final String name = locale.languageCode;
final String localeName = Intl.canonicalizedLocale(name);
return initializeMessages(localeName).then((_) {
Intl.defaultLocale = localeName;
return AppLocalizations();
});
}
String get appTitle => Intl.message(
"My Flutter App",
name: 'appTitle',
desc: 'The title of the application',
);
}
static Future<AppLocalizations> load(Locale locale) async {
final String name = locale.languageCode;
final String localeName = Intl.canonicalizedLocale(name);
return initializeMessages(localeName).then((_) {
Intl.defaultLocale = localeName;
return AppLocalizations();
});
}
String get appTitle => Intl.message(
"My Flutter App",
name: 'appTitle',
desc: 'The title of the application',
);
}
💡 Pro Tip: LocEngine can generate all necessary localization files and Dart code with a single click. It also supports hot reload during development.