Sub topic 1
Internationalization versus localization in Flutter
This chapter defines the two terms that organize the rest of the tutorial and shows which Flutter tools handle each one. Later chapters cover setup and code. This one gives you the model that explains why the setup looks the way it does.
Prerequisites
This chapter assumes you already know the following:
- Basic Dart syntax and null safety.
- How to build a Flutter app from
StatelessWidget,StatefulWidget, andMaterialApp. - How to edit
pubspec.yamland runflutter pub get. - How to read simple JSON and YAML files.
You do not need any localization experience.
Two terms, two jobs
People often use "i18n" and "l10n" as synonyms. They describe different work, done by different people at different times.
- Internationalization (i18n) is preparing the app so it can support many languages and regions without code changes. The abbreviation counts the 18 letters between the "i" and the "n".
- Localization (l10n) is adapting the prepared app to one specific locale: translating the text and choosing the right formats for that language and region. It has 10 letters between the "l" and the "n".
A locale identifies a language, and optionally a script and a region. In Flutter it is a Locale object. Locale('es') means Spanish in general. Locale('es', 'MX') means Spanish as used in Mexico. Locale.fromSubtags(languageCode: 'zh', scriptCode: 'Hans') means Chinese in simplified script.
Internationalization happens once. Localization happens once per locale. A well-internationalized app lets you add Spanish by writing one new file, with no edits to widget code.
What internationalization covers
Internationalization is engineering work. It decides where user-visible text lives and how the app reads it. In Flutter this means:
- No literal user-facing strings in widgets. Text lives in message files, and widgets ask for it by name.
- No string building by concatenation. Word order differs between languages, so
'Hello, ' + name + '!'cannot be translated correctly. Each message must be a whole sentence with placeholders. - No assumptions about plurals. English has two plural forms. Other languages have one, three, or six. The message format has to express plural rules, so code never does
count == 1 ? 'trip' : 'trips'. - No hard-coded formats. Dates, numbers, and currencies are formatted by locale-aware code, never by a pattern you typed such as
'$day/$month/$year'. - Layouts that tolerate change. Translated text can be 30 percent longer than English, and some languages read right to left.
A hard-coded screen shows what to avoid:
import 'package:flutter/material.dart';
void main() => runApp(const MaterialApp(home: HardCodedScreen()));
class HardCodedScreen extends StatelessWidget {
const HardCodedScreen({super.key});
@override
Widget build(BuildContext context) {
const name = 'Ada';
const trips = 1;
return Scaffold(
appBar: AppBar(title: const Text('Trip Planner')),
body: Column(
children: [
// Concatenation fixes the word order.
Text('Hello, ' + name + '!'),
// The plural rule is English-only.
Text('$trips ${trips == 1 ? 'trip' : 'trips'}'),
// The date order is a US convention.
Text('Departs on 3/14/2026'),
],
),
);
}
}This app runs, but every line is a localization blocker. A translator cannot reach any of this text without editing Dart source, and Polish or Arabic plural rules cannot be expressed in the ternary.
What localization covers
Localization is content work. For each supported locale someone provides:
- Translations of every message.
- Plural and gender variants where the language requires them.
- Regional formats for dates, times, numbers, and currencies.
- Text direction. Arabic and Hebrew run right to left. Flutter mirrors layouts built from directional widgets such as
Row,EdgeInsetsDirectional, andAlignmentDirectional. It does not translate anything for you.
The objects that carry locale information are available in any widget. This small screen reports the active locale and text direction:
import 'package:flutter/material.dart';
void main() => runApp(const MaterialApp(home: LocaleInfoScreen()));
class LocaleInfoScreen extends StatelessWidget {
const LocaleInfoScreen({super.key});
@override
Widget build(BuildContext context) {
final locale = Localizations.localeOf(context);
final direction = Directionality.of(context);
return Scaffold(
body: Center(
child: Text('Locale: $locale, direction: $direction'),
),
);
}
}Localizations.localeOf reads the locale chosen for this part of the widget tree. Directionality.of reads the text direction that locale implies. Later chapters cover how Flutter picks the locale.
How the Flutter tools divide the work
Flutter does not ship one "localization" feature. It ships several pieces, and each belongs to one side of the i18n/l10n split.
| Piece | Role | Side |
|---|---|---|
| `flutter_localizations` package | Translations of Flutter's own widget text, such as the "OK" and "Cancel" buttons and date picker labels, for many locales | Localization of the framework |
| `intl` package | Message formatting, plural rules, and date and number formats | Internationalization infrastructure |
| ARB files (`.arb`) | One JSON file per locale holding message text and metadata | Localization content |
| `l10n.yaml` | Tells the generator where files are and what to produce | Internationalization setup |
| `flutter gen-l10n` | Turns ARB files into Dart code | Internationalization tooling |
| `AppLocalizations` | The generated class your widgets call | Internationalization API |
An ARB file (Application Resource Bundle) is a JSON file whose keys are message names and whose values are message text. Keys starting with @ hold metadata about a message, such as a description for translators. One ARB file is the template. It defines every message and its metadata, and the other files only translate it.
The workflow ties these together:
- You add the packages and enable generation.
- You write the template ARB file in your source language.
- A translator adds one ARB file per extra language.
gen-l10ngeneratesAppLocalizations, with one typed method or getter per message.- Widgets call
AppLocalizations.of(context)!.someMessage.
Because step 4 produces real Dart methods, the compiler checks every message call. A missing placeholder or wrong argument type fails the build and does not fail at runtime in front of a user.
Common mistakes at this stage
- Treating translation as the whole job. Teams translate strings and then find that dates, plurals, and layouts still look wrong. Translation is only one part of localization.
- Localizing late. Adding i18n after launch means finding every literal string by hand. Adopting the message API from the first screen costs far less.
- Relying on the device language alone. The device language only picks a locale from the list your app declares. If you declare no locales, the app stays in English.
- Confusing the framework's translations with yours.
flutter_localizationstranslates Flutter's built-in widget text only. It never translates your own messages. - Writing messages as fragments. Messages such as
"Departs on"followed by a separate date widget again fix word order. Keep the whole sentence in one message.
Choosing the template language
The template ARB file sets the shape for every other locale. The messages and placeholders it defines are the only ones the generator guarantees. Pick the language your developers write fluently, because they write the first version of every message. This is usually English. The template does not have to be the default displayed language, but it is the source of truth for message names and types.
Exercise
A teammate adds Spanish support by copying each widget's English string into a Dart Map<String, String> keyed by language code and looking it up with the device language. Name two internationalization problems this still leaves, and say which Flutter piece addresses each.
Show answer
First, plural and word-order rules cannot be expressed in plain map values, so strings like "1 trips" or fixed concatenations remain. ARB messages use ICU plural syntax and placeholders, and gen-l10n generates typed methods for them. Second, dates, numbers, and the framework's own widget text (such as date picker buttons) stay in English or one fixed format. The intl package formats dates and numbers per locale, and flutter_localizations supplies translated Material and Cupertino widget text. A valid answer may also mention that missing keys fail at runtime in a map but at compile time with generated code.
Exercise
Classify each task as internationalization or localization: (a) replacing Text('Save') with a call into generated code, (b) writing the Arabic translation of the save button label, (c) choosing the yMMMd date format for departure dates.
Show answer
(a) Internationalization, because it changes the code once so any locale can be supplied. (b) Localization, because it is content for one specific locale. (c) Internationalization, because the pattern is a locale-neutral skeleton that the intl package renders correctly for each locale.