← Back to posts Cover image for Mastering Flutter Localization: How to QA 23 Languages You Don't Speak (and Prevent ICU Plural Bugs)

Mastering Flutter Localization: How to QA 23 Languages You Don't Speak (and Prevent ICU Plural Bugs)

· 5 min read
Weekly Digest

The Flutter news you actually need

No spam, ever. Unsubscribe in one click.

Chris
By Chris

So your app supports 23 languages, but your team only speaks two. You’ve got a folder full of .arb files, each containing hundreds of key-value pairs. When you tap through the Spanish version, does “Guardar” really mean “Save” or did it accidentally become “Guard” (as in security guard)? Does the Japanese plural rule handle “1 new message” correctly, or is it showing a generic fallback?

This is the silent, lurking challenge of internationalization: verifying what you cannot read. A mistranslation isn’t just awkward—it can break your app’s logic, especially with ICU message formatting for plurals, selectors, and placeholders. Here’s how to build a robust QA process for your Flutter app’s localization, even when you don’t speak the language.

The Core Problem: Silent Fallbacks and ICU Bugs

Flutter’s gen-l10n tool is fantastic, but it operates on trust. If a required translation is missing, it falls back to the base locale (often en). Worse, if an ICU plural statement is malformed, it might fail silently, showing nothing or the raw message ID. You’ll never know until a user in that locale reports it.

Consider this common plural example in your app_en.arb:

"cartItemCount": "{count, plural, =0{Your cart is empty} =1{1 item in cart} other{{count} items in cart}}"

Now, imagine a translator, unfamiliar with the ICU syntax, accidentally alters the structure in another language’s file. The placeholder {count} might get translated, breaking the syntax.

Strategy 1: Pseudo-Localization for Visual Cues

Pseudo-localization doesn’t provide real translations. Instead, it transforms your base strings to help spot issues visually.

  • It can extend text length to reveal layout overflows (e.g., wrapping “Save” into ”[!!! Sâvè !!!]”).
  • It can bracket text to expose untranslated strings.

You can implement a simple pseudo-localization delegate for testing. Create a custom LocalizationsDelegate that wraps your real one. Here’s a basic example:

class PseudoLocalizationsDelegate extends LocalizationsDelegate<MaterialLocalizations> {
  final LocalizationsDelegate<MaterialLocalizations> _realDelegate;
  PseudoLocalizationsDelegate(this._realDelegate);

  @override
  bool isSupported(Locale locale) => locale.languageCode == 'ps'; // Use a pseudo locale code

  @override
  Future<MaterialLocalizations> load(Locale locale) async {
    final realLocalizations = await _realDelegate.load(const Locale('en'));
    return PseudoMaterialLocalizations(realLocalizations);
  }

  @override
  bool shouldReload(covariant LocalizationsDelegate<MaterialLocalizations> old) => false;
}

class PseudoMaterialLocalizations extends MaterialLocalizations {
  final MaterialLocalizations _enLocalizations;

  PseudoMaterialLocalizations(this._enLocalizations);

  @override
  String get okButtonLabel => '[!!! ${_enLocalizations.okButtonLabel} !!!]';

  // Override all other getters similarly, adding brackets and accents.
}

Add this delegate to your localizationsDelegates list when you want to test UI boundaries.

Strategy 2: Automated ICU Syntax Validation

Before you even deploy translations, validate your .arb files. The intl_translation package can help, but you can write a simple pre-build script. The key is to parse each translation value and check for balanced braces {} and valid ICU keywords (plural, select, etc.).

A rudimentary Dart script for your CI pipeline could look like:

import 'dart:io';
import 'package:path/path.dart' as p;

void validateArbFile(String filePath) {
  final file = File(filePath);
  final content = file.readAsStringSync();
  // A very basic check for balanced braces in values.
  // In a real script, use a proper ICU parser or the `intl` package.
  final regex = RegExp(r'"([^"]*)"\s*:\s*"([^"]*)"');
  final matches = regex.allMatches(content);

  for (final match in matches) {
    final value = match.group(2)!;
    final openBraces = '{'.allMatches(value).length;
    final closeBraces = '}'.allMatches(value).length;
    if (openBraces != closeBraces) {
      throw FormatException('Unbalanced braces in value: $value', filePath);
    }
    // Add checks for 'plural' keyword syntax here.
  }
  print('✅ ${p.basename(filePath)} passed basic validation.');
}

void main() {
  final arbFiles = Directory('lib/l10n').listSync().whereType<File>().where((f) => f.path.endsWith('.arb'));
  for (final file in arbFiles) {
    validateArbFile(file.path);
  }
}

Run this script as part of your build process to catch obvious syntax errors early.

Strategy 3: Back-Translation Sampling

This is a powerful technique for catching meaning errors. Use a machine translation API (like Google Cloud Translate) to “back-translate” a random sample of your target language strings back into your native language.

You don’t need to do this for all 10,000 strings. Script a process that:

  1. Selects 5% of keys randomly from each locale file.
  2. Sends them through a translation API to convert them back to English.
  3. Presents you with a simple diff: Original (en): "Save" -> Back-Translated (es->en): "Guard" or "Keep".

A discrepancy like “Guard” for “Save” is a huge red flag. This method helps catch wildly incorrect translations that a pure syntax check would miss.

Strategy 4: Comprehensive Screenshot Testing

Automate visual testing for every supported locale. Use a package like integration_test to programmatically navigate your app, change the locale using WidgetTester, and capture screenshots.

testWidgets('Homepage renders correctly in all locales', (WidgetTester tester) async {
  for (final locale in supportedLocales) {
    await tester.binding.setLocale(locale.languageCode, locale.countryCode ?? '');
    await tester.pumpWidget(const MyApp());
    await expectLater(
      find.byType(MyHomePage),
      matchesGoldenFile('goldens/homepage_${locale.languageCode}.png'),
    );
  }
});

Reviewing these screenshots—even without understanding the text—can reveal glaring issues: text overflow, missing translations (you’ll see the English fallback), or broken UI layouts.

Putting It All Together

Don’t wait for user reports. Integrate these checks into your workflow:

  1. Pre-commit: Run your ICU syntax validator.
  2. Pre-release: Perform a back-translation sample on new or modified strings.
  3. CI Pipeline: Run pseudo-localization and screenshot tests for critical flows.
  4. Manual QA: Use a simple locale picker in your debug builds to let testers switch languages on the fly.

By combining automated validation, visual testing, and strategic sampling, you move from blind trust to confident verification. You’ll catch the “Guardar” that should have been “Guardar (para ahorrar)” long before it reaches your users, ensuring a polished experience in all 23 languages.

This blog is produced with the assistance of AI by a human editor. Learn more

Related Posts

Cover image for Choosing the Right Storage for Flutter: Beyond SharedPreferences for Persistent Data

Choosing the Right Storage for Flutter: Beyond SharedPreferences for Persistent Data

Developers frequently struggle with persistent storage in Flutter, especially when dealing with OS-level backups and app reinstalls. This post will clarify the nuances of different storage solutions like `SharedPreferences`, `path_provider`, and `flutter_secure_storage`, focusing on how to correctly manage data lifetimes (per-install vs. per-user) and avoid issues like device IDs migrating to new phones or data being unexpectedly backed up.

Cover image for Optimizing Flutter UI Performance: Solving `ImageFiltered` Lag and Smooth Blurring

Optimizing Flutter UI Performance: Solving `ImageFiltered` Lag and Smooth Blurring

Flutter's `ImageFiltered` can cause significant lag when blurring large or frequently changing content like text. This post will explain the performance bottlenecks, provide solutions like caching blurred outputs with `RepaintBoundary` or `SnapshotWidget`, and offer practical tips to ensure smooth UI effects without sacrificing frame rates.