How to Translate Flutter ARB Files Without Breaking Plurals & Metadata
Flutter's Application Resource Bundle (.arb) is a powerful JSON-based i18n format—until machine translation tools butcher your @message descriptions, flatten ICU plural forms, or translate Dart variable placeholders. Here is how to automate ARB translation safely.
TL;DR — Key Takeaways
- Standard translation engines break Flutter ARB files by translating
@metakeys and mangling placeholders like{count}. - StrucTrans tokenizes ARB structures, masking ICU patterns (
plural,select) and preserving metadata intact. - Output ARB files instantly compile with Flutter's official
flutter gen-l10nwithout Dart compilation errors.
Why Traditional Machine Translation Destroys Flutter ARB Files
Flutter's internationalization engine relies on intl and Application Resource Bundles (.arb). Unlike standard JSON, ARB files interleave localization data with critical metadata:
Mangled Metadata
Generic tools translate keys starting with @ (e.g. @welcomeUser or @@locale), corrupting the context rules Flutter uses to generate Dart code.
Broken ICU Plural Rules
Expressions like {count, plural, =0{Zero} other{Many}} get translated into plain English words, causing FormatException in Dart.
Renamed Variable Tokens
Variables like {userName} become {nombreDeUsuario} in Spanish, breaking signature contracts in your Flutter widgets.
Raw Translation vs StrucTrans AST-Safe ARB Output
{
"@@locale": "es",
"@bienvenido": "Mensaje de bienvenida",
"bienvenido": "¡Hola, {nombre}!",
"items": "plurar, =0{Sin elementos}"
} Keys translated, @-metadata decoupled, ICU syntax corrupted.
{
"@@locale": "es",
"welcome": "¡Hola, {name}!",
"@welcome": { "description": "Welcome message" },
"itemCount": "{count, plural, =0{Sin elementos} other{{count} elementos}}"
} Keys & @-metadata preserved 100%, ICU expressions tokenized safely.
Complete Flutter ARB Translation Workflow
Follow this 4-step pipeline to localize your Flutter app in minutes.
Prepare Your Template ARB File (app_en.arb)
Ensure your base language file defines @@locale and includes explicit metadata blocks for variables so Flutter's intl code generator can bind types accurately:
{
"@@locale": "en",
"appTitle": "Fleet Manager",
"userGreeting": "Welcome back, {username}!",
"@userGreeting": {
"description": "Greeting shown on homepage header",
"placeholders": {
"username": {
"type": "String",
"example": "Alex"
}
}
}
} Translate Online with StrucTrans
Upload your app_en.arb file directly into the StrucTrans ARB Translator. Select target languages (Spanish, German, French, Japanese, Ukrainian).
- Keys (
appTitle,userGreeting) remain untouched. - Metadata fields (
description,type,example) are locked. - Placeholders (
{username}) stay exactly as defined.
Save Target File (e.g., app_es.arb)
Download the translated ARB file and save it in your project's lib/l10n/ directory alongside your primary ARB file.
lib/
l10n/
app_en.arb
app_es.arb
app_de.arb
app_uk.arb
l10n.yaml Run flutter gen-l10n
Execute the Flutter localization code generator terminal command:
$ flutter gen-l10n
Because syntax integrity was preserved 100%, Flutter immediately generates compiled AppLocalizations Dart code without throwing syntax or missing variable errors.
Frequently Asked Questions
How do I translate Flutter .arb files without breaking @-metadata?
Standard translation tools treat @-prefixed entries like @hello or @@locale as translatable strings. StrucTrans uses an AST-aware parser that locks all @-metadata and placeholder definitions, translating only the actual human message strings.
Does auto-translation support Flutter ICU plural and select expressions?
Yes. ICU plural constructs such as {count, plural, =0{No items} =1{1 item} other{{count} items}} are tokenized. Keywords (=0, =1, other, plural) and variable tokens remain untouched while string values are safely translated.
How does translated ARB integrate with flutter gen-l10n?
Once translated, your target ARB file (e.g. app_es.arb) retains identical key structure and placeholder contracts. Running 'flutter gen-l10n' automatically compiles type-safe Dart classes like AppLocalizations.of(context)!.hello(username).
Is StrucTrans free for Flutter developers?
Yes. You can upload and translate Flutter .arb files directly in your browser for free, without registration or complex subscription setups.
Ready to Localize Your Flutter App in Seconds?
Upload your .arb file, preserve all @-metadata and ICU rules, and get production-ready translations instantly.