By Updated •7 min read

Flutter Localization: ARB Examples, Language Switching, and RTL

FlutterLocalizationi18nARBRTL
Flutter localization guide showing multi-language support and RTL layout

Introduction

To localize a Flutter app, define messages in ARB files, generate AppLocalizations into your source tree, and register its delegates and supported locales in MaterialApp. Arabic and Urdu also need right-to-left layout testing; translating strings alone does not verify the interface.

This guide is for developers adding English, Arabic, or Urdu to an existing Flutter app. It uses the current source-generated localization workflow and a small app with no external state-management dependency. The example is checked against Flutter 3.47.2 and Dart 3.13.2; pin your own SDK and dependency lockfile when adopting it.

My work on BeesApp includes Arabic/English localization. The three-language example below is an independent teaching example, not a claim that BeesApp ships an Urdu interface.

Configure localization generation in the source tree

From an existing Flutter project, install the SDK localization package and a compatible intl version:

flutter pub add flutter_localizations --sdk=flutter
flutter pub add intl:any

Flutter's internationalization guide uses dependency resolution to choose an intl version compatible with the SDK. Commit pubspec.lock for an application, then review upgrades deliberately rather than copying an old intl constraint.

In the existing flutter section of pubspec.yaml, enable generation:

flutter:
  uses-material-design: true
  generate: true

Create l10n.yaml beside pubspec.yaml:

arb-dir: lib/l10n
output-dir: lib/l10n/generated
template-arb-file: app_en.arb
output-localization-file: app_localizations.dart
output-class: AppLocalizations
nullable-getter: false

Use the generated source file directly. Flutter has removed the synthetic package:flutter_gen workflow; imports into .dart_tool/flutter_gen should be migrated. With the configuration above, the import from lib/main.dart is l10n/generated/app_localizations.dart.

Create ARB files with placeholders and plural rules

Create lib/l10n/app_en.arb:

{
  "@@locale": "en",
  "appTitle": "Recipe library",
  "languageLabel": "Language",
  "welcome": "Welcome, {name}",
  "@welcome": {
    "description": "Greeting on the library screen",
    "placeholders": {"name": {"type": "String", "example": "Moeen"}}
  },
  "itemCount": "{count, plural, =0{No recipes} one{1 recipe} other{{count} recipes}}",
  "@itemCount": {
    "description": "Number of recipes in the library",
    "placeholders": {"count": {"type": "int"}}
  }
}

Create lib/l10n/app_ar.arb:

{
  "@@locale": "ar",
  "appTitle": "مكتبة الوصفات",
  "languageLabel": "اللغة",
  "welcome": "مرحباً، {name}",
  "itemCount": "{count, plural, =0{لا توجد وصفات} one{وصفة واحدة} two{وصفتان} few{{count} وصفات} many{{count} وصفة} other{{count} وصفة}}"
}

Create lib/l10n/app_ur.arb:

{
  "@@locale": "ur",
  "appTitle": "ترکیبوں کی لائبریری",
  "languageLabel": "زبان",
  "welcome": "خوش آمدید، {name}",
  "itemCount": "{count, plural, =0{کوئی ترکیب نہیں} one{ایک ترکیب} other{{count} ترکیبیں}}"
}

These translations illustrate ICU message structure. Have a fluent reviewer check the wording in its actual UI context. Arabic has plural categories beyond English's one and other; the Unicode plural rules describe how categories depend on the locale and number.

Generate the files:

flutter gen-l10n

A missing or malformed placeholder should be resolved at generation time. Do not manually edit generated Dart files; edit the ARB source and regenerate.

Wire delegates, supported locales, and runtime switching

The following replaces lib/main.dart in the small example app:

import 'package:flutter/material.dart';
import 'l10n/generated/app_localizations.dart';

void main() => runApp(const LocalizedApp());

class LocalizedApp extends StatefulWidget {
  const LocalizedApp({super.key});

  @override
  State<LocalizedApp> createState() => _LocalizedAppState();
}

class _LocalizedAppState extends State<LocalizedApp> {
  Locale? _locale;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      locale: _locale,
      supportedLocales: AppLocalizations.supportedLocales,
      localizationsDelegates: AppLocalizations.localizationsDelegates,
      onGenerateTitle: (context) => AppLocalizations.of(context).appTitle,
      home: LibraryScreen(
        selectedLocale: _locale,
        onLocaleChanged: (locale) => setState(() => _locale = locale),
      ),
    );
  }
}

class LibraryScreen extends StatelessWidget {
  const LibraryScreen({
    super.key,
    required this.selectedLocale,
    required this.onLocaleChanged,
  });

  final Locale? selectedLocale;
  final ValueChanged<Locale> onLocaleChanged;

  @override
  Widget build(BuildContext context) {
    final l10n = AppLocalizations.of(context);
    final active = selectedLocale ?? Localizations.localeOf(context);

    return Scaffold(
      appBar: AppBar(title: Text(l10n.appTitle)),
      body: ListView(
        padding: const EdgeInsetsDirectional.fromSTEB(24, 16, 24, 24),
        children: [
          Text(l10n.welcome('Moeen')),
          Text(l10n.itemCount(3)),
          const SizedBox(height: 24),
          Text(l10n.languageLabel),
          DropdownButton<Locale>(
            value: active,
            isExpanded: true,
            items: const [
              DropdownMenuItem(value: Locale('en'), child: Text('English')),
              DropdownMenuItem(value: Locale('ar'), child: Text('العربية')),
              DropdownMenuItem(value: Locale('ur'), child: Text('اردو')),
            ],
            onChanged: (locale) {
              if (locale != null) onLocaleChanged(locale);
            },
          ),
        ],
      ),
    );
  }
}

The generated delegates include both your messages and framework localizations. With _locale set to null, Flutter resolves the device's preferences against the generated supported locales. An explicit user selection overrides that choice for this app session.

This example deliberately does not persist the choice. In your application, load a stored language code before choosing the initial locale, validate it against supported locales, and persist later selections. Keep a separate “Use device language” option if users need to return to automatic resolution.

Test RTL layouts and mixed-direction content

Framework widgets can inherit RTL direction, but custom positioning still needs care.

UI concernPreferVerify
Asymmetric paddingEdgeInsetsDirectional.only(start: 16, end: 8)Leading space follows the language
AlignmentAlignmentDirectional.centerStartLabels align with reading direction
Positioned elementsPositionedDirectionalBadges and controls stay attached correctly
Navigation iconsDirection-aware IconData, such as Icons.arrow_backNavigation mirrors where appropriate
Email, URLs, identifiersA narrowly scoped LTR Directionality where neededMixed strings remain readable and selectable

matchTextDirection belongs to IconData, not an Icon constructor parameter. Avoid double-mirroring an icon that already follows text direction. Media controls, brand marks, and diagrams may need to retain their original orientation.

For example, keep a support email readable inside an otherwise RTL screen:

const Directionality(
  textDirection: TextDirection.ltr,
  child: SelectableText('support@example.com'),
)

Use this around the relevant field, not the entire Arabic page. Test Arabic mixed with product names, phone numbers, amounts, and long translations. Review font shaping and text scaling on real devices. Our GCC Flutter engineering guide covers broader regional product considerations.

Add a localization regression test

In the example project, replace the generated counter test with a test importing LocalizedApp from your package. If the package is named l10n_refresh_demo, use:

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:l10n_refresh_demo/main.dart';

void main() {
  testWidgets('switches to Arabic and inherits RTL', (tester) async {
    await tester.pumpWidget(const LocalizedApp());
    await tester.pumpAndSettle();

    await tester.tap(find.byType(DropdownButton<Locale>));
    await tester.pumpAndSettle();
    await tester.tap(find.text('العربية').last);
    await tester.pumpAndSettle();

    expect(find.text('مكتبة الوصفات'), findsOneWidget);
    expect(
      Directionality.of(tester.element(find.text('مرحباً، Moeen'))),
      TextDirection.rtl,
    );
    expect(tester.takeException(), isNull);
  });
}

This checks locale switching and inherited text direction. It does not prove translation quality, every screen's layout, or every plural branch. Add cases for counts 0, 1, 2, 3, 11, and 100, narrow screens, large text, Urdu, and device-language fallback. Use screenshot or golden comparisons for important RTL screens; see the Flutter testing guide.

Format values and negotiate backend language separately

Use DateFormat and NumberFormat from intl with the active locale's language tag:

final locale = Localizations.localeOf(context);
final tag = locale.toLanguageTag();

A locale does not determine which currency your business uses; choose the currency code explicitly. Check the actual output instead of assuming every Arabic locale uses identical digits and punctuation.

For APIs, send a language preference through Accept-Language, keep stable error codes, and let the server define fallback behavior. A header does not translate content by itself. If caching translated responses, include the language in the cache strategy. Continue with language-aware FastAPI responses for that boundary.

Conclusion

A localized Flutter app needs generated messages, correct locale resolution, and UI verification in each supported language.

  • Generate localization classes under lib, and import their real source path.
  • Keep placeholder types and locale-specific plural rules in ARB files.
  • Separate a device-selected locale from an explicit user choice.
  • Verify directional layouts, mixed text, fonts, and accessibility.
  • Treat backend language handling and translation review as separate responsibilities.

Planning an Arabic, Urdu, or English mobile release? Book a project discussion to review localization coverage and the tests needed before launch.

Share

See the project work

Explore the decisions, scope, and validation behind selected mobile and AI projects.

Explore case studies