Flutter

Flutter Localization

Localize a Flutter application: keep its strings in an ARB file, translate it in Soluling, and let Flutter compile the localized ARB files into the application.

Flutter has its own localization: the strings are in ARB files, and flutter gen-l10n generates the AppLocalizations class from them. Soluling reads the template ARB file, keeps the descriptions for the translator, opens the ICU plurals and selects in the pattern editor, and writes an ARB file for each language. Translate in Soluling Desktop or in a browser with Soluling Cloud, and update the translations over the air without a new release. The tutorial uses the Driving sample, a small driving time calculator.

Try Soluling

Resources ARB app_en.arb Soluling Original (English) Translation (Finnish) Driving Time Driving distance Driving speed Calculate hours hour / hours hours minutes minute / minutes minutes Ajoaika Ajomatka Ajonopeus Laske hours tunti / hours tuntia minutes minuutti / minutes minuuttia The strings in app_en.arb have been translated Localized resources ARB app_en.arb fi app_fi.arb de app_de.arb ja app_ja.arb A localized ARB file for each language, compiled by flutter gen-l10n Resources ARB app_en.arb Soluling Original (English) Translation (Finnish) Driving Time Driving distance Driving speed Calculate hours hour / hours hours minutes minute / minutes minutes Ajoaika Ajomatka Ajonopeus Laske hours tunti / hours tuntia minutes minuutti / minutes minuuttia The strings in app_en.arb have been translated Localized resources ARB app_en.arb fi app_fi.arb de app_de.arb ja app_ja.arb A localized ARB file for each language, compiled by flutter gen-l10n
One Flutter build holds every language, and the application chooses the language of the device or the one the user selects.
Input
The template ARB file, such as lib/l10n/app_en.arb
Output
Localized ARB files, such as app_fi.arb, next to the template
Runtime
AppLocalizations, generated by flutter gen-l10n, shows the messages of the application's locale
Cloud
Upload the ARB file to Soluling Cloud directly, and update the translations over the air

On this page

Tutorial

Localize a Flutter application, step by step

Six steps take the Driving sample from an English-only application to a multilingual one.

01

Prepare: move the strings to app_en.arb

Add the localization packages, and turn on the code generation in pubspec.yaml. Then add l10n.yaml, which tells flutter gen-l10n where the ARB files are and which one is the template:

# pubspec.yaml
dependencies:
  flutter_localizations:
    sdk: flutter
  intl: any

flutter:
  generate: true

# l10n.yaml
arb-dir: lib/l10n
template-arb-file: app_en.arb
output-localization-file: app_localizations.dart

Write the strings of the original language into lib/l10n/app_en.arb, each with a key, and describe them for the translator with an @ entry:

{
  "@@locale": "en",
  "drivingTime": "Driving Time",
  "@drivingTime": {
    "description": "The title of the page"
  },
  "result": "Driving time is {hours, plural, one{{hours} hour} other{{hours} hours}} {minutes, plural, one{{minutes} minute} other{{minutes} minutes}}",
  "@result": {
    "description": "The calculated driving time",
    "placeholders": {
      "hours": { "type": "int" },
      "minutes": { "type": "int" }
    }
  }
}

Then give MaterialApp the delegates and locales of the generated class, and replace every text the user sees with its getter:

// lib\main.dart
MaterialApp(
  localizationsDelegates: AppLocalizations.localizationsDelegates,
  supportedLocales: AppLocalizations.supportedLocales,
  onGenerateTitle: (context) => AppLocalizations.of(context)!.appTitle,
  ...
);

var l10n = AppLocalizations.of(context)!;

Text(l10n.drivingTime);
Text(l10n.result(hours, minutes));

From Flutter 3.47 on, Material is its own package, material_ui. Its widgets need the translations of material_ui's GlobalMaterialLocalizations, so list them yourself, with AppLocalizations.delegate, as the Driving sample does.

02

Add: create a Soluling project

Drag and drop lib/l10n/app_en.arb on Soluling. In the Select File Type dialog, select Flutter resource file: the file is also valid generic JSON, but only this parser reads the descriptions and the placeholders, and keeps the @ entries. Add the target languages, and click Finish. If the localized files already exist, such as app_fi.arb, Soluling imports their translations.

Creating the project lib/l10n/app_en.arb goes through the Select File Type dialog (Flutter resource file) and Select Languages page (Finnish, German, Japanese). Resource file lib\l10n\app_en.arb Select file type Flutter resource file Languages Finnish (fi) German (de) Japanese (ja) Select Flutter resource file, not the generic JSON file.
Moving the texts to the ARB file Before, the title and the result are hard-coded English. After, they use the getters of AppLocalizations, and the result is a message with plural forms. app_en.arb has the texts, with Finnish translations. Before: a hard-coded page Text('Driving Time') Text('Driving time is $hours hour(s) ...') ✕ Stays English, no plural forms Internationalize After: lib\main.dart Text(l10n.drivingTime) Text(l10n.result(hours, minutes)) app_en.arb and app_fi.arb in Soluling drivingTime Finnish Ajoaika result English {hours} hour / {hours} hours Finnish {hours} tunti / {hours} tuntia ✓ The keys, the texts, and the plural forms of each language
The generated getters and methods check the placeholders at compile time: result takes the hours and the minutes as integers.
03

Translate: texts, placeholders, and plural forms

Each message is a row in the grid, with its description as the comment. Placeholders such as {hours} are protected: the translator moves them but doesn't change them. A plural or select message opens in the pattern editor, which shows the forms that the target language needs: Finnish has one and other, Polish one, few, many, and other, and Japanese only other. Soluling writes the ICU syntax of each language back.

  • Machine translation and translation memory. Click Use Machine Translation to translate with Amazon, Claude, DeepL, Google, Microsoft, ModernMT, or MyMemory, and reuse earlier translations from translation memory and terminology.
  • External translators. Send a translation package, an Excel file, or XLIFF to a translator, and import the results back. See teamwork.
  • Translators in a browser. Upload the project to Soluling Cloud and let translators work in Translate.
04

Check: find problems before release

Pseudo translation. Click Translate | Pseudo Translations | Fill, build, and run the application. Pseudo translations are longer and use accented characters, so texts that don't fit and strings still in the code (shown in plain English) stand out. See pseudo translation.

Pseudo-translated build

[Ðŕîvîñĝ Ţîɱé ___] PS Driving distance 220 Driving speed 88 [Çåļçûļåţé ______________] [Çåļçûļåţé ______________] [Ðŕîvîñĝ ţîɱé îš 2 ĥôûŕš 30 ɱîñûţéš ________] Too long and still English (hard-coded)

Validation. Soluling validates translations while you type and in batch (Validation | Validate Translations): missing translations, inconsistent placeholders and patterns, duplicate hotkeys, and more. See validation.

Validation

⚠ Inconsistent format string result (German) The original has {hours} and {minutes}; the translation has only {hours}: Die Fahrzeit beträgt {hours, plural, ...} ⚠ Missing translation speedHint (Japanese) The field shows the English text.

flutter gen-l10n also fails when a translation has a placeholder that the template doesn't have, so a broken translation never reaches a release build.

05

Build: create the localized ARB files

Choose Home | Build All. Soluling writes app_fi.arb, app_de.arb, and app_ja.arb into lib/l10n, with the descriptions and placeholders of the template. Then build the application as usual: flutter run or flutter build runs flutter gen-l10n, which compiles every ARB file into AppLocalizations and adds its language to supportedLocales. There is no code to change for a new language.

ARB files and the generated classes lib\l10n has the template app_en.arb and the localized files app_fi.arb, app_de.arb, and app_ja.arb. flutter gen-l10n generates app_localizations.dart and a class for each language next to them. Soluling: Build All DIR lib\l10n\ ARB app_en.arb template: written by you ARB app_fi.arb localized: the same keys ARB app_de.arb ARB app_ja.arb Flutter: flutter gen-l10n DIR lib\l10n\ DART app_localizations.dart the AppLocalizations class DART app_localizations_fi.dart a class for each language
06

Update: translate only what changed

When you add or change strings in app_en.arb, click Home | Scan. Soluling keeps the existing translations, adds the new strings, and marks the rows whose original text changed. Translate the new rows, build, and build the application. Add the scan and build steps to your build pipeline with SoluMake or, with Soluling Cloud, SoluCLI.

Reference

The ARB file

An ARB file is JSON. Each message has a key and a text; an entry with the same key and an @ before it describes the message, and the @@locale entry tells the language of the file:

{
  "@@locale": "en",
  "hello": "Hello {name}!",                          // a placeholder
  "@hello": {
    "description": "A greeting",                    // the comment for the translator
    "placeholders": {
      "name": { "type": "String", "example": "Maija" }
    }
  },
  "price": "Price: {amount}",
  "@price": {
    "placeholders": {
      "amount": { "type": "double", "format": "currency", "optionalParameters": { "name": "EUR" } }
    }
  }
}

The type and format of a placeholder decide how its value is formatted: a number with NumberFormat, such as compact or currency, and a date with a DateFormat skeleton, such as yMd. Flutter formats them in the language of the application, so the translation keeps only the placeholder. The description is shown to the translator as the comment of the row, and the example as part of it.

Plurals and selects

Flutter's messages use the ICU syntax. A plural has a form for each plural category of the language, chosen by the count, and a select a form for each value, such as a gender:

"hours": "{count, plural, =0{no hours} one{{count} hour} other{{count} hours}}",
"driver": "{gender, select, female{She drove} male{He drove} other{They drove}}"

Soluling opens these in the pattern editor, which has a field for each form that the target language needs, and checks that the translation has the same structure. =0 is an exact value, and the other keys are the CLDR categories zero, one, two, few, many, and other. A message can have several plurals, such as the result of the Driving sample, which has one for the hours and one for the minutes.

Escaping

By default, { and } are always the braces of a placeholder or a plural. With use-escaping: true in l10n.yaml, text in single quotes is literal, such as '{name}', and two single quotes are a quote. Turn on the same option, Use escaping, in the options of the Flutter source in Soluling, so that it reads the messages the way Flutter does.

Fallback

flutter gen-l10n uses the template's text for a key that a localized ARB file doesn't have, so an untranslated string shows the original text. A device language without an ARB file of its own uses the closest supported locale: fi_FI uses app_fi.arb, and a language that the application doesn't have uses the first locale of supportedLocales.

Message lookup for a device in fi_FI For a device in fi_FI, Flutter chooses the fi locale. drivingTime and calculate are in app_fi.arb as Ajoaika and Laske. A string that was not translated uses the text of app_en.arb, the template. UI culture: fi_FI fi_FI the closest supported locale app_fi.arb app_en.arb the template drivingTime – ✓ Ajoaika calculate – ✓ Laske aNewString – not translated ✓ A new string

Choose and change the language

By default, the application uses the language of the device. To let the user choose, keep the chosen locale in the state of the root widget, and give it to MaterialApp: the whole application is built again in the new language.

class _DrivingAppState extends State<DrivingApp> {
  Locale? _locale;   // null: the language of the device

  @override
  Widget build(BuildContext context) => MaterialApp(
    locale: _locale,
    ...
    home: DrivingPage(onLocaleChanged: (locale) => setState(() => _locale = locale)),
  );
}

Translate in Soluling Cloud

With Soluling Cloud, translators use Translate in a browser. How you start depends on what you localize:

  • Flutter ARB files (.arb). On the dashboard, add a project, select lib/l10n/app_en.arb, and choose Flutter resource file as the source type. Translators work in Translate; click Build localized files, and save the downloads to lib/l10n as app_fi.arb and so on, or let SoluCLI open a pull request with them. When the application changes, upload the new app_en.arb; the existing translations are kept. No desktop step is needed.

To run the scan, upload, import, and build steps in your build pipeline, use SoluMake. See the Cloud tutorial and workflows.

Update the translations over the air

When you translate in Soluling Cloud and publish the project's files, the application can use them over the air: a translation fix or a new language reaches your users without a new release or an app store review. The translations that Flutter compiled stay in the application. soluling_ota downloads the published ARB files and uses their translations in place of the compiled ones; a message without a downloaded translation shows the compiled one.

flutter pub add soluling_ota
dart run soluling_ota:generate     # after flutter gen-l10n: writes lib/l10n/ota_localizations.dart

// lib\main.dart
Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await SolulingOta.init('1b6e2f0a-4c2d-4e9a-9f1a-0123456789ab');
  runApp(const DrivingApp());
}

MaterialApp(
  localizationsDelegates: [
    OtaLocalizations.delegate,                 // in place of AppLocalizations.delegate
    ...GlobalMaterialLocalizations.delegates,
  ],
  supportedLocales: OtaLocalizations.supportedLocales,
  ...
);

The generator reads l10n.yaml, the template ARB file, and the class that flutter gen-l10n generated, and writes a subclass of AppLocalizations whose getters and methods return the downloaded translation. The rest of the application doesn't change: AppLocalizations.of(context)!.drivingTime gives the downloaded text when there is one. Run the generator again when the ARB files change.

A downloaded file can't be compiled into the application, so the package formats its messages itself, with the same rules: the placeholders, the plural categories of the language, selects, and the number and date formats of the placeholders. SolulingOta.init uses the translations downloaded before at once, and checks for newer ones in the background once a day, so a fix is used on the next start. On the first start it waits for the first download for three seconds at most. SolulingOta.instance.update() checks now and uses newer translations at once, such as for a Check for new translations button.

Make the Soluling Cloud project from lib/l10n/app_en.arb, with Flutter resource file as the source type, and turn on Publish artifacts on the Integrations tab of the project's Manage page. OtaLocalizations.supportedLocales has the languages published in Soluling Cloud too, so a language added after the release can be chosen. A downloaded translation is not used when it can't be parsed, has a placeholder that the original doesn't have, or is the translation of a text that a later version of the application changed. The package works on Android, iOS, macOS, Windows, and Linux, but not on the web.

See the OTA sample (Samples\Flutter\Ota), the soluling_ota reference, and over-the-air updates for how publishing works.

Do and don't

Do

  • Move every text the user sees to the ARB file, including the title from onGenerateTitle.
  • Describe each message with a description, and each placeholder with an example.
  • Give each text a short, stable key.
  • Write whole sentences with placeholders, and give the placeholders a type.
  • Use ICU plurals and selects.
  • Pseudo-translate before the first real translation.

Don't

  • Build sentences from pieces in code.
  • Use the English text as the key; the key changes when the text changes.
  • Choose plural forms with if statements; other languages have other rules.
  • Add app_en.arb as a generic JSON file; the descriptions and placeholders are lost.
  • Format numbers and dates in code and pass them as text; give the placeholder a type and a format.

Typical localizability problems

See also internationalization and pseudo translation.

Problem How it shows Find and fix
Hard-coded texts Labels and hints in English in a pseudo-translated build Move the text to app_en.arb, and use its getter.
Texts read too early The old language stays after the user changes it Read AppLocalizations.of(context) in build, not once in initState or a global variable.
Sentences built from pieces Word order and plurals are wrong in the translation Use one message with placeholders and an ICU plural.
Numbers formatted in code English decimal points in the Finnish build Pass the number, and give the placeholder a type and a format.
Fixed widths Clipped or overflowing text in the pseudo or German build Let the layout grow with the text, such as with Flexible and Wrap.

Troubleshooting

Symptom Likely cause What to do
AppLocalizations is not found The code has not been generated Set generate: true in pubspec.yaml, and run flutter gen-l10n.
The application stays in English The device's language has no ARB file, or MaterialApp lacks the delegates Build the language's ARB file, and set localizationsDelegates and supportedLocales.
No MaterialLocalizations found Flutter 3.47 or later, where Material is the material_ui package Add material_ui's GlobalMaterialLocalizations.delegates to the delegates.
flutter gen-l10n reports a placeholder error A translation has a placeholder that the template doesn't have Fix the translation in Soluling; validation shows the row.
Descriptions are missing in Soluling The file was added as a generic JSON file Create the project again with Flutter resource file.

Samples

The samples are in Samples\Flutter of the Soluling installation and on GitHub:

  • Ota: the driving time calculator of this guide, localized into Finnish, German, and Japanese, with a language selector, over-the-air translation updates from Soluling Cloud, and the Soluling project, Ota.ntp. See Update the translations over the air.
  • Simple and Escape: ARB files with placeholders and plurals, and with escaping, and their Soluling projects.

See Flutter localization in the Desktop documentation for all the details.

FAQ

Flutter's own: ARB files and flutter gen-l10n. It is what the Flutter documentation recommends, the generated getters are checked at compile time, and the messages use the ICU syntax.

Yes. Upload the ARB file to Soluling Cloud, translate in Translate, and download the localized files. See Translate in Soluling Cloud.

Yes. soluling_ota downloads the translations published in Soluling Cloud and uses them in place of the compiled ones, so a fix or a new language reaches your users without a new release or an app store review. See Update the translations over the air.

No. One build holds every language that has an ARB file, and the application chooses at runtime.

Add it to the Soluling project, translate, and build. The new ARB file adds the language to supportedLocales on the next flutter gen-l10n, with no code changes. With over-the-air updates, a language published in Soluling Cloud reaches the installed applications too.

Yes. The pattern editor shows the forms that each language needs, such as one, few, many, and other in Polish, and Soluling writes them as ICU into the ARB file.

Related

All guides