Flutter Localization: Multi-Language Apps
Most of the world does not read English as a first language, and a large share of the people who install your app will never be comfortable in it. An app that only speaks English quietly tells those users that it was not built for them, and most of them leave without ever telling you why.
Localization is the fix, and in Flutter it is mostly mechanical: translated strings live in ARB files, the flutter_localizations package wires them into the framework, and the generated AppLocalizations class gives every widget a type-safe way to read them.
This guide sets up localization the way it ships in production apps: ARB files for each language, plurals and placeholders handled properly, a runtime language switcher that persists the user's choice, and dates and numbers formatted per locale. The example adds English and Spanish, and the same steps scale to eight languages - the Sleep Sounds app on this site ships in eight languages using exactly this approach.
What is Flutter localization?
Flutter localization is the process of adapting an app's text, dates, numbers and layout to the user's language and region, using ARB files for the translated strings and the flutter_localizations package to load them.
The app ships one ARB file per language, for example app_en.arb for English and app_es.arb for Spanish, and Flutter picks the file that matches the device locale at runtime. Nothing in the widget tree changes: the same Text widget renders "Hello" for an English user and "Hola" for a Spanish user, because both strings come from the same generated accessor.
Localization is not the same as translation done by hand in code. Hardcoded if (locale == 'es') branches do not scale past two languages and are impossible to hand to a translator. ARB files are JSON with a standard structure, so translators and translation tools can work with them directly, and the Flutter tooling generates a Dart class from them, which means a missing or misspelled string becomes a compile error instead of a blank label at runtime.
Dates, numbers and currency follow the same rule: the intl package formats them per locale, so 12 March 2026 renders as March 12, 2026 in English and 12 de marzo de 2026 in Spanish without any branching in your code.
What do I need to set up localization?
Setting up localization in Flutter needs three things: the flutter_localizations package, the intl package, and a small l10n.yaml configuration file.
Add the dependencies first:
dependencies:
flutter:
sdk: flutter
flutter_localizations:
sdk: flutter
intl: any
Then create l10n.yaml at the project root, next to pubspec.yaml. It tells the generator where the ARB files live and what to name the generated class:
arb-dir: lib/l10n
template-arb-file: app_en.arb
output-localization-file: app_localizations.dart
Run flutter pub get, then flutter gen-l10n to generate the localization code. From this point on, the generation also runs automatically on every build, so you only need to run it manually when you want the new strings available in the IDE immediately.
If the generated class does not appear, the usual cause is a missing flutter_localizations dependency or an l10n.yaml in the wrong folder: it must sit at the project root, not inside lib.
How do ARB files work?
An ARB file is a JSON file with one entry per string, plus metadata entries that start with @. The template file lib/l10n/app_en.arb holds the English strings, and every other language file mirrors its keys exactly:
{
"@@locale": "en",
"appTitle": "My App",
"@appTitle": {
"description": "The title shown in the app bar"
},
"hello": "Hello {name}",
"@hello": {
"description": "Greeting on the home screen",
"placeholders": {
"name": {
"type": "String",
"example": "Uzair"
}
}
},
"nItems": "{count, plural, =0{No items} =1{One item} other{{count} items}}",
"@nItems": {
"description": "Number of items in the list",
"placeholders": {
"count": {
"type": "int"
}
}
}
}
The @hello metadata is not decoration. It declares the {name} placeholder with its type, so the generator produces a method hello(String name) instead of a plain string, and it gives translators the context they need to translate the sentence correctly. A placeholder without metadata is a compile error, which is the system working as intended: it catches the mistake before the app ships.
The Spanish file only needs the translations and its own locale marker:
{
"@@locale": "es",
"appTitle": "Mi App",
"hello": "Hola {name}",
"nItems": "{count, plural, =0{Sin elementos} =1{Un elemento} other{{count} elementos}}"
}
Note the plural entry. English has two plural forms in this example, but the ICU plural syntax in the ARB file handles the general rule, and languages with more forms - Arabic has six - get their own plural branches in their own ARB file. Never write plural logic in Dart with count == 1 ? 'item' : 'items', because that rule is wrong in most of the world's languages. Put the rule in the ARB file and let the intl package apply it.
How do I use translated strings in widgets?
Once the code is generated, wire the delegates and supported locales into MaterialApp. The generated class exposes both, so there is nothing to list by hand:
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
MaterialApp(
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
home: const HomeScreen(),
);
localizationsDelegates is the list of objects that know how to load translations for each locale, and supportedLocales is derived from the ARB files in lib/l10n, so adding a new language is just adding one ARB file.
Inside a widget, read strings through AppLocalizations.of(context):
final l10n = AppLocalizations.of(context)!;
Text(l10n.appTitle);
Text(l10n.hello('Uzair'));
Text(l10n.nItems(3));
The ! is safe here as long as the delegates are set up, because of(context) returns null only when no delegate can provide localizations - which is the first thing to check if you see a null error.
A small extension keeps the call sites tidy:
extension LocalizationX on BuildContext {
AppLocalizations get l10n => AppLocalizations.of(this)!;
}
With that in place, widgets read context.l10n.hello('Uzair'), which is short enough that nobody is tempted to hardcode a string instead.
One rule makes the whole system hold together: no user-facing string may live outside an ARB file. The moment a button label or an error message is hardcoded in Dart, that string is English forever, and no translator will ever find it.
How do I switch language at runtime?
By default Flutter follows the device locale, which is the right default for most apps. But users expect a language setting inside the app too, especially when the device language is not the language they want your app in.
The switch is a single locale property on MaterialApp, driven by state that survives restarts:
class LocaleNotifier extends ChangeNotifier {
Locale _locale = const Locale('en');
Locale get locale => _locale;
Future setLocale(Locale locale) async {
_locale = locale;
final prefs = await SharedPreferences.getInstance();
await prefs.setString('locale', locale.languageCode);
notifyListeners();
}
Future loadSavedLocale() async {
final prefs = await SharedPreferences.getInstance();
final code = prefs.getString('locale');
if (code != null) {
_locale = Locale(code);
notifyListeners();
}
}
}
Add shared_preferences: any to pubspec.yaml, load the saved locale before runApp, and pass the notifier's locale into MaterialApp:
MaterialApp(
locale: localeNotifier.locale,
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
home: const HomeScreen(),
);
Changing the locale rebuilds the whole app with the new strings, because MaterialApp rebuilds when its locale changes. The language picker itself is a simple list of the supported locales with their native names - "English", "EspaΓ±ol", "Deutsch" - built from AppLocalizations.supportedLocales, so it never goes stale when a language is added.
Keep the locale state in one place, for example a ChangeNotifier like the one above or a view model if the app already uses one; the MVVM pattern fits naturally here, with the locale living in the view model and the picker calling one method on it.
A word of warning: storing the locale as a bare string in shared preferences is fine, but always validate it against supportedLocales on load, or a locale saved by an older app version can leave the app with no matching translations.
How do I handle plurals, dates and numbers?
Plurals are handled in the ARB file, as shown above, and dates and numbers go through the intl package with the active locale. The generated localizations class exposes localeName, which is the locale string to pass to the formatters:
final l10n = context.l10n;
final date = DateFormat.yMMMMd(l10n.localeName).format(DateTime.now());
final price = NumberFormat.simpleCurrency(locale: l10n.localeName).format(49.99);
DateFormat.yMMMMd renders 23 November 2026 in English and 23 de noviembre de 2026 in Spanish. NumberFormat.simpleCurrency picks the right currency symbol and grouping for the locale. Both take the locale explicitly, so they keep working even when the widget is built outside the normal localization context, for example inside a dialog built from a service class.
The common mistake is formatting dates with toString() or by concatenating day, month and year by hand: that output is wrong in every locale except the one the developer happened to test in.
Right-to-left languages deserve a mention because they change layout, not just text. Adding Arabic or Urdu is the same ARB-file step as any other language, and Flutter flips the layout automatically: Row, Padding and alignment resolve through Directionality, which MaterialApp sets from the locale. The catch is hardcoded left and right values - EdgeInsets.only(left: 16) does not flip, while EdgeInsetsDirectional.only(start: 16) does. If the app will ever support an RTL language, use the directional variants from the start.
What goes wrong most often?
Most localization bugs come from the setup, not the translations, and they all share one trait: the app builds fine and the problem only appears at runtime.
- Missing
flutter_localizationsdependency - Symptom:AppLocalizations.of(context)returns null - Fix: Add the SDK dependency and runflutter pub get - ARB key missing in one language - Symptom: Generated method exists, translation falls back to English - Fix: Keep every ARB file's keys identical to the template
- Placeholder without metadata - Symptom:
flutter gen-l10nfails with a placeholder error - Fix: Add the@keyentry with the placeholder type - Hardcoded strings left in widgets - Symptom: Some labels never translate - Fix: Grep for string literals in widgets before release
- Layout overflow in long languages - Symptom: German or French text clips or overflows - Fix: Use
Flexible,ExpandedandTextwithsoftWrap - Locale saved by an old version - Symptom: App opens with no matching translations - Fix: Validate the saved code against
supportedLocaleson load
The fallback rule is worth knowing: when the device locale has no matching ARB file, Flutter falls back to the first entry in supportedLocales, which is the template language - English, in this setup. That is a safe default, but it is not a substitute for translating the strings users actually see.
Also, remember that adding a language is not just an ARB file: the Play Store listing, screenshots and app description need the same language, or users will find the app in their language and read a listing in English.
The short version
Flutter localization is a small, mechanical setup with an outsized payoff: ARB files hold the strings, flutter_localizations loads them, and the generated AppLocalizations class makes every string type-safe. Put plurals and placeholders in the ARB file, never in Dart. Drive the locale property of MaterialApp from state so users can switch language inside the app, persist the choice, and format dates and numbers with the intl package.
Do that, and the app speaks the user's language on day one - including the eight languages the Sleep Sounds app ships in - instead of waiting for a rewrite that never comes.
Get in touch and let's talk about your project.
Originally published at uzairxdev.online
Comments
No comments yet. Start the discussion.