---
title: "How to translate your Flutter app and edit your .arb files"
description: "Free tutorial: Learn how to translate your Flutter app and comfortably work with Application Resource Bundle (.arb) files. Example source code included."
canonical: "https://www.codeandweb.com/babeledit/tutorials/how-to-translate-your-flutter-apps"
date: "2022-12-14T00:00:00.000Z"
modified: "2022-12-14T00:00:00.000Z"
source: "html"
---

# How to translate your Flutter app and edit your .arb files

Andreas Löw, Joachim Grill, Daniel Sperl

[babeledit](https://www.codeandweb.com/babeledit/tutorials.md),  [tutorial](https://www.codeandweb.com/tags/tutorial),  [flutter](https://www.codeandweb.com/tutorials/flutter.md)

[GitHub](https://github.com/CodeAndWeb/Flutter-Translation-Example)

![How to translate your Flutter app and edit your .arb files](https://www.codeandweb.com/static/bc92acf0f40e55500e580075cb324aec/a6312/how-to-translate-your-flutter-apps.png)

> **Note:** This is the updated version of the tutorial. It uses the current version of Flutter and the intl package. An older version supporting intl 0.13.1 is available here:
>
> [How to translate your Flutter app and edit your .arb files (using intl 0.13.1)](https://www.codeandweb.com/babeledit/tutorials/how-to-translate-your-flutter-apps-intl-0.13.1)

In this tutorial we explain how to quickly set up translations for your Flutter app. The first two sections explain how to set up a simple demo application — feel free to skip it ;-)

We've created this tutorial on a Mac using Flutter's web target. This means that the app will run in Chrome. We assume that it should be easy enough for you to adapt the steps to run on Windows or Linux and/or run the app on an iPhone or Android device; if a platform requires any additional steps, we'll mention them along the way.

## Prepare a simple demo project

### Install Flutter

```bash
git clone https://github.com/flutter/flutter.git
export PATH=$PATH:$(pwd)/flutter/bin
```

Alternatively Flutter can be downloaded as zip archive from [flutter.dev](https://docs.flutter.dev/get-started/install/macos)

### Create and launch the demo app in Chrome

```bash
flutter create myapp
cd myapp
flutter run
```

## Setup internationalization

### Add the required dependencies to your project

Add these lines to `dependencies:` in `pubspec.yaml`

```yaml
dependencies:
  flutter:
    sdk: flutter
  flutter_localizations:
    sdk: flutter
  intl:
```

Run `flutter pub get packages` to download those packages to your project folder.

The other change inside `pubspec.yaml` is to enable the `generate` flag. This is added to the section of the pubspec that is specific to Flutter, and usually comes a little further down.

```yaml
# The following section is specific to Flutter.
flutter:
  generate: true
```

Next, import the `flutter_localizations` library in `lib/main.dart` and pass `localizationsDelegates` and `supportedLocales` to the _MaterialApp_ constructor.

```dart
import 'package:flutter_localizations/flutter_localizations.dart';
...

class MyApp extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      ...
      localizationsDelegates: [
          GlobalMaterialLocalizations.delegate,
          GlobalWidgetsLocalizations.delegate,
          GlobalCupertinoLocalizations.delegate
      ],
      supportedLocales: [
          const Locale('en', ''), // English
          const Locale('de', ''), // German
      ],
      ...
```

Beware that iOS requires us to specify the supported locales in the Xcode project, as well. So, if you're deploying to iOS, open `ios/Runner.xcodeproj` with Xcode and add "German" to the Localizations of the project:

   ![How to translate your Flutter application](https://www.codeandweb.com/static/4c79ff69c567c31a9731009fb3e04af9/283d3/add-localization-to-xcode-project-1.png)  ![How to translate your Flutter application](https://www.codeandweb.com/static/f405bdcf8a86dca5464b42d893fe61bc/283d3/add-localization-to-xcode-project-2.png)

`flutter run` should still compile and run the app successfully. Flutter texts are now localized, but localization of our own texts is still missing.

### Set up templates for ARB files

Add a new yaml file to the root directory of the Flutter project called `l10n.yaml`. Paste the following content:

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

This configures where the specific localization files are going to be found.

*   The input files (with all the translated data) will be found in `lib/l10n`.
*   The file `app_en.arb` will contain the English Strings. It will act as a template for all other languages.
*   The class that provides access to the Strings at runtime will be generated in `app_localizations.dart`.

Let's create that template file, `lib/l10n/app_en.arb`:

```json
{
    "pushCounterText": "You have pushed the button this many times:"
}
```

That's the first text we're going to use in our app. Let's add a German translation right away, via the new file `lib/l10n/app_de.arb`:

```json
{
    "pushCounterText": "Du hast den Button so oft gedrückt:"
}
```

Now, run your app so that codegen takes place.

```bash
flutter run
```

Of course, the text is still only English (we're not really loading our translation yet). But you should see a few generated files in `.dart_tool/flutter_gen/gen_l10n`.

### Add localization class

Import the auto-generated class into your code, right at the top of `main.dart`.

```dart
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
```

Now we need to update the _MaterialApp_ constructor. That new generated class provides two helpers that simplify setting up delegates and locales. Let's make use of that:

```dart
return MaterialApp(
  title: 'Flutter Demo',
  localizationsDelegates: AppLocalizations.localizationsDelegates, // <- here
  supportedLocales: AppLocalizations.supportedLocales, // <- and here
  ...
```

Finally, we can make use of our translated text!

Look for this text widget inside the _build_\-method of _MyHomePageState_:

```dart
Text('You have pushed the button this many times:'),
```

Replace it with a call to the new _AppLocalizations_ class:

```dart
Text(AppLocalizations.of(context)!.pushCounterText);
```

(Note the `!`, which means our app is compiled with _sound null safety_, as is now the default in Dart.)

This code creates a widget that displays the corresponding German or English text. Each key in the _arb_\-file is used as method name of the getter, which means you can comfortably access them via code completion.

### Run localized app

Let's give this a test run to see if we were actually successful.

```bash
flutter run
```

This will compile your app and run it inside Chrome. Unless German is your native language, the browser will probably still display the English text. In that case, open a new tab and navigate here: `chrome://settings/languages`. Add "German" as a language and move it to the top of the list.

Hurray! The Flutter demo will immediately change the text.

  ![Flutter application with English localizations](https://www.codeandweb.com/static/0ed2a7d8cde6ef2bffdf411fdfc12264/283d3/app-chrome-en.png)

  ![Flutter application with German localizations](https://www.codeandweb.com/static/9199c1903b1e9996bee073b7b8cee104/283d3/app-chrome-de.png)

### How to add more translations

To add more translations, you simply edit `app_en.arb` and `app_de.arb`, adding new texts along the way, e.g.:

app\_en.arb:

```json
{
  "pushCounterText": "You have pushed the button this many times:",
  "appTitle": "Localization Hero"
}
```

app\_de.arb:

```json
{
  "pushCounterText": "Du hast den Button so oft gedrückt:",
  "appTitle": "Mehrsprachen-Held"
}
```

Then you can use the strings in your application:

```dart
// ...
appBar: AppBar(
  title: Text(AppLocalizations.of(context)!.appTitle),
),
// ...
```

When running the app after adding a new text, your IDE will likely present you with a warning that build errors exist in your project. This is because the _AppLocalizations_ class will need to be re-generated for the `appTitle` property to be available.

So it's recommended to first add the text resource, then compile your app — and only then start using it. Alternatively, you can ignore the error, as it will be fixed on first run, anyway. For example, in VSCode, you can run the Flutter app by selecting "Debug Anyway" in the build error dialog that appears.

## Simplify your translation workflow

Editing the `.arb` translation files will get a bit cumbersome over the time:

*   You have to escape the strings to write proper .json files.
*   You have to open and update all language files manually.
*   The .arb files may become difficult to read over time, especially if you add any metadata.

A much simpler workflow is possible if you use BabelEdit:

*   BabelEdit automatically inserts the new translations in all files and keeps them in sync
*   The nice user interface only displays relevant information
*   Use features like pre-translate to automatically create translations for other languages
*   Export and import into other formats (e.g. Excel) to send to translators
*   Spellchecker

You can download BabelEdit for Windows, macOS and Linux from here:

[Download BabelEdit 5.7.0](https://www.codeandweb.com/babeledit/download/5.7.0/win)

for Windows

[Also available for macOS and Linux](https://www.codeandweb.com/babeledit/download.md)

Start BabelEdit after the installation and simply drag & drop your project directory into the main window. Click on the **Flutter ARB** project:

  ![Translate your Flutter application with BabelEdit](https://www.codeandweb.com/static/e7a2ebc4aa8c31ccd04b5da8b55c4a81/283d3/translate-your-flutter-application.png)

BabelEdit now searches the project folder for .arb files and presents them with a guess for the languages contained in the files. Confirm _de_ and _en_.

  ![Select the language for your flutter translation files](https://www.codeandweb.com/static/23ac6a17451f4bf97ca7cb789874b296/283d3/add-flutter-translation-files-and-set-language.png)

Select your primary language — that is the language that you use in your main translations. It's used as the source language for features like pre-translate. Select **en-US** by clicking on the **configure** button:

  ![Select english as source language](https://www.codeandweb.com/static/82873a41e5052b81a277287598d05990/283d3/select-english-as-source-language-for-machine-translation.png)

BabelEdit now automatically displays suggestions for your translations:

  ![How to pre-translate your .arb files](https://www.codeandweb.com/static/71e03115d1daab7ba3572b0a51120438/283d3/how-to-pre-translate-your-arb-files.png)

Finally, save the files using the **save** button from the toolbar. BabelEdit asks you for the name and location of a .babel file — BabelEdit's project file that contains all project relevant settings.

It also updates your .arb files with the translations.

## Structured data

```json
{
  "@context": "https://schema.org",
  "@type": "TechArticle",
  "headline": "How to translate your Flutter app and edit your .arb files",
  "author": [
    {
      "@type": "Person",
      "name": "Andreas Löw"
    },
    {
      "@type": "Person",
      "name": "Joachim Grill"
    },
    {
      "@type": "Person",
      "name": "Daniel Sperl"
    }
  ],
  "dateModified": "2022-12-14T00:00:00.000Z",
  "image": "/static/bc92acf0f40e55500e580075cb324aec/a6312/how-to-translate-your-flutter-apps.png"
}
```
