[ Flutter ]

Wrap Flutter widgets for gen-l10n automatically

Dart string literals become AppLocalizations getters, keys land in your ARB files (merged, never clobbered), and l10n.yaml drives Flutter's own code generation.

1 Min. LesezeitAlle Frameworks

Flutter's official i18n is flutter gen-l10n: ARB catalogs in, generated AppLocalizations getters out. Polyglot automates the part the toolchain doesn't — finding your hardcoded strings and converting them.

The transformation

Before — lib/home.dart
import 'package:flutter/material.dart';

class Home extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Text("Welcome back");
  }
}
After — lib/home.dart
import 'package:flutter/material.dart';
import 'package:demo_app/l10n/app_localizations.dart';

class Home extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Text(AppLocalizations.of(context)!.welcome_back);
  }
}
  • The whole string literal is replaced with the getter — never a partial splice inside Dart interpolation.
  • const contexts are respected: a const Text(...) can't hold a runtime lookup, so those strings are skipped with a reason rather than broken.
  • The AppLocalizations import is added per file, and resolves via your l10n.yaml — which Polyglot scaffolds if missing.

ARB catalogs, merged

Written — lib/l10n/app_en.arb
{
  "@@locale": "en",
  "welcome_back": "Welcome back"
}
Translated — lib/l10n/app_de.arb
{
  "@@locale": "de",
  "@welcome_back": {
    "description": ""
  },
  "welcome_back": "Willkommen zurück"
}
Translated — lib/l10n/app_fr.arb
{
  "@@locale": "fr",
  "@welcome_back": {
    "description": ""
  },
  "welcome_back": "Bon retour"
}

Existing ARB entries are read and preserved; keys are flat identifiers exactly as gen-l10n requires, so the generated getters always match the wrapped call sites.

✓ 1 strings auto-wrapped · 0 flagged for manual review · 0 unsafe transforms → polyglot-i18n-report.md
✓ wiring checks passed (1 injected import(s), 1 catalog value(s), 1 catalog file(s))

Try it

$ curl -fsSL https://getpolyglot.ai/install.sh | sh
$ polyglot init --framework flutter
$ polyglot scan
$ polyglot wrap
$ polyglot translate --languages de   # 50 strings free, no signup

Im Terminal starten

Schluss mit der Suche nach unübersetzten Strings.

Installieren Sie die CLI, führen Sie einen Scan durch und sehen Sie genau, was Ihnen fehlt. Kostenlos, kein Konto erforderlich.

$curl -fsSL https://getpolyglot.ai/install.sh | sh
Wrap Flutter widgets for gen-l10n automatically | Polyglot