Sub topic 1
Internationalization versus localization in Flutter
Prerequisites
This chapter assumes that you can read basic Dart syntax, use null safety, and build a Flutter app with MaterialApp, StatelessWidget, and StatefulWidget. You should also know how to edit YAML and JSON files and run Flutter commands such as flutter pub get.
Two related ideas
Internationalization, often written as i18n, is the work of designing an app so it can support different languages and regions. The name comes from the first and last letters of internationalization, with 18 letters between them.
Localization, or l10n, is the process of adapting that prepared app for one specific locale. A locale identifies language and regional preferences, such as en_US for English in the United States or fr_FR for French in France.
The distinction matters because an app can be translated without being properly internationalized. For example, replacing English labels with French text is localization. Making the layout handle longer French sentences, formatting dates correctly, and allowing right-to-left text requires internationalization.
| Concern | Meaning | Flutter example |
|---|---|---|
| Internationalization | Preparing the app for many locales | Avoiding fixed-width text areas |
| Localization | Supplying content for one locale | Providing French translations |
| Locale | A language and regional preference | `en_US` or `de_DE` |
| Message | Text shown to the user | “Save trip” |
How Flutter uses localized messages
A localized Flutter app usually has four layers:
- The app identifies the current locale.
- Flutter chooses the best supported locale.
- Localization resources provide messages for that locale.
- Widgets read those messages instead of containing fixed user-facing text.
ARB, or Application Resource Bundle, is the translation file format commonly used with Flutter's gen-l10n tool. An ARB file contains message keys, translated text, and optional metadata. The tool reads these files and generates a Dart class named AppLocalizations.
The generated class gives widgets a typed way to request messages. A widget can ask for a message such as appTitle without knowing whether the current text comes from English, Spanish, or another translation file.
Common errors
A frequent mistake is putting user-facing text directly in widgets:
Text('Plan trip')This text cannot change when the locale changes. It also makes it easy for different screens to use inconsistent wording. Store the message in localization resources and access it through the generated localization class instead.
Another mistake is treating a language as a complete locale. Spanish used in Spain and Spanish used in Mexico may need different words, date formats, or number formats. Use the most specific locale your product supports.
Text length is also part of internationalization. German labels may be longer than English labels. Arabic and Hebrew use right-to-left layouts. Some languages change plural rules. Therefore, do not assume that a label fits because it fits in English.
The working model
Think of localization as data selected at runtime, not as a collection of conditional statements:
- The locale describes the user's language and region.
- The supported-locale list describes what the app can provide.
- ARB files contain the messages.
gen-l10nturns those messages into Dart APIs.- Widgets use those APIs and remain independent of the actual language.
This separation lets the interface code focus on layout and behavior while translation files handle language-specific content.
Exercise
Is replacing every English string with a French string enough to internationalize an app?
Show answer
No. That is localization for one language. Internationalization also prepares layouts, formatting, direction, locale selection, and message handling for multiple locales.