Auto-Generate Flutter Translations

Stop forgetting to regenerate your Flutter translations! 🚀

I got tired of manually running dart run intl_utils:generate every time I edited my .arb translation files. So I automated it with a simple file watcher script.

How to use it:
Just run this c…


This content originally appeared on DEV Community and was authored by Mostafa Ead

Stop forgetting to regenerate your Flutter translations! 🚀

I got tired of manually running dart run intl_utils:generate every time I edited my .arb translation files. So I automated it with a simple file watcher script.

How to use it:
Just run this command in your terminal:

dart run scripts/watch_translations.dart

The script will watch your lib/l10n directory and automatically regenerate translations whenever you modify any .arb file.

Here's the implementation:

import 'dart:io';

void main() async {
  final l10nDir = Directory('lib/l10n');

  if (!l10nDir.existsSync()) {
    print('Error: lib/l10n directory does not exist');
    exit(1);
  }

  print('Watching for changes in lib/l10n/*.arb files...');
  print('Press Ctrl+C to stop\n');

  // Watch the directory
  await for (final event in l10nDir.watch()) {
    if (event.path.endsWith('.arb') && event.type == FileSystemEvent.modify) {
      print('Detected change in: ${event.path}');
      print('Generating translations...');

      final result = await Process.run(
        'dart',
        ['run', 'intl_utils:generate'],
        runInShell: true,
      );

      if (result.exitCode == 0) {
        print('âś“ Translations generated successfully\n');
      } else {
        print('âś— Error generating translations:');
        print(result.stderr);
      }
    }
  }
}

What it does:
âś… Monitors the lib/l10n directory for changes to .arb files
âś… Detects when translation files are modified
âś… Automatically runs the translation generation command
âś… Provides clear feedback on success or failure

Now I can edit translation files and the generated code updates automatically. No more manual steps or missed regenerations.

The script uses Dart's built-in Directory.watch() API to monitor file system events. It's lightweight, runs in the background, and has been a huge time-saver.

Sometimes the best solutions are the simplest ones that remove friction from your workflow.

Flutter #Dart #MobileDevelopment #DeveloperProductivity #Automation #FlutterDev #Coding #SoftwareDevelopment


This content originally appeared on DEV Community and was authored by Mostafa Ead


Print Share Comment Cite Upload Translate Updates
APA

Mostafa Ead | Sciencx (2025-11-03T20:51:03+00:00) Auto-Generate Flutter Translations. Retrieved from https://www.scien.cx/2025/11/03/auto-generate-flutter-translations/

MLA
" » Auto-Generate Flutter Translations." Mostafa Ead | Sciencx - Monday November 3, 2025, https://www.scien.cx/2025/11/03/auto-generate-flutter-translations/
HARVARD
Mostafa Ead | Sciencx Monday November 3, 2025 » Auto-Generate Flutter Translations., viewed ,<https://www.scien.cx/2025/11/03/auto-generate-flutter-translations/>
VANCOUVER
Mostafa Ead | Sciencx - » Auto-Generate Flutter Translations. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/11/03/auto-generate-flutter-translations/
CHICAGO
" » Auto-Generate Flutter Translations." Mostafa Ead | Sciencx - Accessed . https://www.scien.cx/2025/11/03/auto-generate-flutter-translations/
IEEE
" » Auto-Generate Flutter Translations." Mostafa Ead | Sciencx [Online]. Available: https://www.scien.cx/2025/11/03/auto-generate-flutter-translations/. [Accessed: ]
rf:citation
» Auto-Generate Flutter Translations | Mostafa Ead | Sciencx | https://www.scien.cx/2025/11/03/auto-generate-flutter-translations/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.