runTranslationTool function

Future<void> runTranslationTool({
  1. String? srcFile,
  2. String? lang,
})

Main function called from CLI

Implementation

Future<void> runTranslationTool({String? srcFile,String? lang}) async {




  // args[0] = input file path (optional, default: lib/core/app_strings.dart)
  // args[1] = source language (optional, default: 'ar')
  // args[2] = target languages comma-separated (optional, default: 'en,fr')

  final inputPath = srcFile ?? 'lib/core/app_strings.dart';
  final sourceLang = lang ?? 'ar';
  final targetLangs =
      ['ar','en', 'fr'];

  print('📌 Input file: $inputPath');
  print('📌 Source language: $sourceLang');
  print('📌 Target languages: $targetLangs');

  final file = File(inputPath);
  if (!file.existsSync()) {
    stderr.writeln('❌ Input file not found: $inputPath');
    return;
  }

  final content = file.readAsStringSync();
  final keys = extractKeys(content);

  if (keys.isEmpty) {
    stderr.writeln('⚠️ No matches found. Check regex or file format.');
    return;
  }

  generateLocaleKeys(keys);

  // Process each target language
  for (final lang in targetLangs) {
    await updateJson(lang, keys, sourceLang);
  }

  print('✅ Localization update completed for all target languages.');
}