runTranslationTool function
Main function called from CLI
Implementation
Future<void> runTranslationTool({String? srcFile,String? lang}) async {
final inputPath = srcFile ?? 'lib/core/app_strings.dart';
final sourceLang = lang ?? 'ar' ;
final targetLangs =
['ar','en', 'fr'];
final file = File(inputPath);
if (!file.existsSync()) {
print('\x1B[31m❌ ERROR: File not found!\x1B[0m');
print('📁 Path Must Be: $inputPath');
exit(1);
}
// ✅ File exists — now check if it's empty
final fileSize = file.lengthSync();
if (fileSize == 0) {
print('\x1B[33m⚠️ WARNING: File is empty!\x1B[0m');
} else {
print('\x1B[32m✅ File found and not empty.\x1B[0m');
print('📏 Size: $fileSize bytes');
}
final content = file.readAsStringSync();
final keys = extractKeys(content);
if (keys.isEmpty) {
print('📌 Before staring, make sure to define your keys like this:');
print('📌 Input file: $inputPath');
print('📌 Source language: $sourceLang');
print('📌 Target languages: $targetLangs');
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.');
// print('📌 Input file: $inputPath');
// print('📌 Source language: $sourceLang');
// print('📌 Target languages: $targetLangs');
}