सामग्री पर जाएँ
Flutter i18n

Flutter i18n: एक कोडबेस, हर भाषा, हर प्लेटफ़ॉर्म

Flutter एक ही codebase से iOS, Android, web, और desktop पर localization को संभालने के लिए ARB (Application Resource Bundle) फ़ाइलों और intl package का उपयोग करता है। gen-l10n tool आपके ARB templates से type-safe Dart code generate करता है, जो आपको हर translation key के लिए compile-time safety और IDE autocomplete प्रदान करता है।

Get started in 4 steps

1

Enable generation

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

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

flutter:
  generate: true
2

Configure l10n.yaml

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

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

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

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'));
  }
}

फ्लटर स्थानीयकरण सुविधाएँ

ICU MessageFormat syntax और metadata समर्थन के साथ ARB file format
टाइप-सेफ़ अनुवादों के लिए gen-l10n के माध्यम से स्वचालित डार्ट कोड जेनरेशन
आईसीयू बहुवचनकरण और चयन नियम संकलन-समय सत्यापन के साथ
iOS, Android, वेब और डेस्कटॉप के लिए एकल कोडबेस स्थानीयकरण
विकास के दौरान तत्काल translation preview के लिए hot reload समर्थन
तारीखों, text direction, और accessibility के लिए Material और Cupertino widget localizations
स्वचालित टेक्स्ट और विजेट संरेखण के साथ दाएँ-से-बाएँ (RTL) लेआउट समर्थन
intl package के माध्यम से locale-aware date, number, और currency formatting
AppLocalizations.of(context) के साथ BuildContext-आधारित locale access

व्यवहार में Flutter Localization

बहुवचन और date formatting के पूर्ण समर्थन के साथ, अपने widgets में generated translation methods तक पहुंचने के लिए AppLocalizations.of(context) का उपयोग करें।

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())),
      ],
    );
  }
}

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. Better i18n stores and exports translations in ARB format natively.

How does Better i18n integrate with Flutter's localization workflow?

Better i18n connects to Flutter projects via the CLI. Run `better-i18n push` to upload your template ARB file (app_en.arb), have translators or AI complete translations in the dashboard, then run `better-i18n pull` to download all localized ARB files into your lib/l10n/ directory. The Flutter build system then regenerates the type-safe AppLocalizations class. This replaces manual file exchange with translators and keeps all languages in sync.

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. Better i18n's translation editor supports ICU syntax and validates plural forms for each target language.

What is the better_i18n Flutter package?

better_i18n is Better i18n's official Flutter/Dart SDK on pub.dev. It fetches translations from the Better i18n CDN at runtime, supporting over-the-air translation updates without requiring an app store release. The SDK implements a two-phase load pattern: it reads from local SharedPreferences storage first for instant display, then fetches fresh translations from the CDN in the background. Storage keys are compatible with the JavaScript SDKs.

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 Better i18n, you add the language in the dashboard, AI pre-translates all existing keys, your team reviews them, and you pull the ARB file with `better-i18n pull`. 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.

आज ही Flutter Localization को सरल बनाएं

AI-संचालित वर्कफ़्लो, अपने Flutter प्रोजेक्ट में CLI sync, और 50ms से कम CDN डिलीवरी के साथ अपने ARB अनुवादों को प्रबंधित करें।