Zum Inhalt springen
Flutter i18n

Flutter i18n: Ein einziger Code, alle Sprachen, alle Plattformen

Flutter nutzt ARB-Dateien (Application Resource Bundle) und das intl-Paket, um die Lokalisierung für iOS, Android, das Web und den Desktop aus einer einzigen Codebasis heraus zu verwalten.

Messages
ARB
Sync
npx lefine strings pull
flutter_localizations · gen_l10n
01lib/l10n/app_en.arb
{  "@@locale": "en",  "welcome": "Welcome to {appName}",  "@welcome": {    "placeholders": {      "appName": { "type": "String" }    }  },  "itemCount": "{count, plural, =0{No items} =1{1 item} other{{count} items}}",  "@itemCount": {    "placeholders": {      "count": { "type": "int" }    }  }}
02product_page.dart
import 'package:flutter_gen/gen_l10n/app_localizations.dart';class ProductPage extends StatelessWidget {  final int itemCount;  const ProductPage({required this.itemCount});  @override  Widget build(BuildContext context) {    final l10n = AppLocalizations.of(context)!;    return Column(      children: [        Text(l10n.welcome('My Store')),        Text(l10n.itemCount(itemCount)),        // Date formatting respects locale        Text(DateFormat.yMMMd(          Localizations.localeOf(context).toString()        ).format(DateTime.now())),      ],    );  }}
l10n.welcome('My Store')
Welcome to My Store

Flutter-Lokalisierung in der Praxis

Verwenden Sie `AppLocalizations.of(context)`, um in Ihren Widgets auf generierte Übersetzungsmethoden zuzugreifen, wobei Pluralisierung und Datumsformatierung vollständig unterstützt werden.

01/Overview

Das Tool „gen-l10n“ generiert typsicheren Dart-Code aus Ihren ARB-Vorlagen und bietet Ihnen so Sicherheit bei der Kompilierung sowie eine IDE-Autovervollständigung für jeden Übersetzungsschlüssel.

02/Setup

Get started in 4 steps

  1. 01

    Enable generation

    Add the generate flag to your pubspec.yaml to enable localization code generation.

    pubspec.yaml
    # pubspec.yamldependencies:  flutter:    sdk: flutter  flutter_localizations:    sdk: flutter  intl: anyflutter:  generate: true
  2. 02

    Configure l10n.yaml

    Create l10n.yaml in your project root to configure the localization generator.

    l10n.yaml
    # l10n.yamlarb-dir: lib/l10ntemplate-arb-file: app_en.arboutput-localization-file: app_localizations.dart
  3. 03

    Create ARB template

    Add your source language ARB file with translation keys and metadata.

    lib/l10n/app_en.arb
    {  "@@locale": "en",  "welcome": "Welcome to {appName}",  "@welcome": {    "placeholders": {      "appName": { "type": "String" }    }  },  "itemCount": "{count, plural, =0{No items} =1{1 item} other{{count} items}}",  "@itemCount": {    "placeholders": {      "count": { "type": "int" }    }  }}
  4. 04

    Use in your app

    Wrap your app with localization delegates and use AppLocalizations.of(context) in widgets.

    lib/main.dart
    import 'package:flutter_gen/gen_l10n/app_localizations.dart';class MyApp extends StatelessWidget {  @override  Widget build(BuildContext context) {    return MaterialApp(      localizationsDelegates: AppLocalizations.localizationsDelegates,      supportedLocales: AppLocalizations.supportedLocales,      home: MyHomePage(),    );  }}class MyHomePage extends StatelessWidget {  @override  Widget build(BuildContext context) {    final l10n = AppLocalizations.of(context)!;    return Text(l10n.welcome('Flutter'));  }}
03/Capabilities

Lokalisierungsfunktionen von Flutter

  • ARB-Dateiformat mit ICU-MessageFormat-Syntax und Unterstützung für Metadaten
  • Automatische Dart-Code-Generierung über gen-l10n für typsichere Übersetzungen
  • ICU-Pluralisierung und Auswahlregeln mit Validierung zur Kompilierungszeit
  • Lokalisierung aus einer einzigen Codebasis für iOS, Android, Web und Desktop
  • Unterstützung für Hot Reload zur sofortigen Vorschau der Übersetzung während der Entwicklung
  • Lokalisierungen für Material- und Cupertino-Widgets in Bezug auf Datumsangaben, Textrichtung und Barrierefreiheit
  • Unterstützung für das Layout von rechts nach links (RTL) mit automatischer Ausrichtung von Text und Widgets
  • Länderspezifische Formatierung von Datumsangaben, Zahlen und Währungen mithilfe des intl-Pakets
  • Zugriff auf die Ländereinstellung über BuildContext mit AppLocalizations.of(context)
04/FAQ

Flutter i18n — Frequently Asked Questions

What are ARB files and why does Flutter use them?
ARB (Application Resource Bundle) files are JSON-based localization files used by Flutter's official gen_l10n tool. Each ARB file contains translation key-value pairs plus metadata (placeholders, descriptions, plural rules) in @-prefixed entries. Flutter's build system generates type-safe Dart code from ARB files, so accessing translations via AppLocalizations.of(context).myKey is fully typed and IDE-autocompleted. Lefine does not read or write ARB files: its CLI and CDN deliver translations as JSON.
How does Lefine integrate with Flutter's localization workflow?
Lefine connects to Flutter apps through the CLI. Create keys in the dashboard or with `npx lefine strings push`, have translators or AI complete translations, then run `npx lefine strings publish` to put them on the CDN. `npx lefine strings pull` downloads each locale as a <locale>.json file (into the folder you pass with -o) that you can bundle as Flutter assets and load with rootBundle or the i18n package you already use. Lefine does not import or export ARB files, so if you keep gen_l10n and AppLocalizations, your ARB files stay the source of truth for that path.
Does Flutter support ICU message format for plurals?
Yes. Flutter's gen_l10n tool uses ICU MessageFormat syntax for plural and select messages in ARB files. For example: '{count, plural, =0{No items} =1{1 item} other{{count} items}}'. The generated Dart code handles the correct plural form selection based on the active locale's CLDR plural rules. Lefine's quality checks on AI translations flag a translation that drops an ICU plural or select branch, loses the # placeholder, or renames the argument.
Is there a Lefine Flutter package?
Lefine has no Flutter package of its own. The path that works today is the CLI: `npx lefine strings pull` writes one JSON file per locale, you list the folder under `flutter: assets:` in pubspec.yaml, and your code reads the file for the active locale with rootBundle. Run pull again after each publish to refresh the files.
How do I add a new language to a Flutter app?
Add the locale to your MaterialApp's supportedLocales list, create a corresponding ARB file (app_fr.arb for French) in your l10n directory, then run `flutter gen-l10n` to regenerate the AppLocalizations class. With Lefine, you add the language in the dashboard, AI can pre-translate the existing keys, your team reviews them, and after `npx lefine strings publish` you run `npx lefine strings pull` to get the new <locale>.json file for your app. If you also use gen_l10n, the new ARB file is still yours to create. The entire process — from adding a language to having production-ready translations — takes hours instead of weeks.
Does Flutter i18n work on all platforms — iOS, Android, web, and desktop?
Yes. Flutter's localization system is cross-platform by design. The same ARB files and AppLocalizations class work identically on iOS, Android, web, macOS, Windows, and Linux. Platform-specific behaviors like date formats, number separators, and RTL text direction are handled by the flutter_localizations package and the intl library, which implements Unicode CLDR rules for each locale.
Get started

Kostenlos starten.

Vereinfachen Sie noch heute die Lokalisierung von Flutter

Verwalten Sie Ihre Flutter-Übersetzungen mit KI-gestützten Workflows und CDN-Bereitstellung an das Paket better_i18n.