execute static method

void execute({
  1. required String locationMultiLangKeys,
  2. required String pathFolder,
})

This function will replace all 'string'.tr format into MultiLangKeys.string.tr

Implementation

static void execute({
  required String locationMultiLangKeys,
  required String pathFolder,
}) async {
  print("Convert 'string'.tr to MultiLangKeys.string.tr");
  try {
    /// Get all the path files of the projects
    List<String> pathFiles = await FolderReader.getAllFilePaths(pathFolder);
    if (pathFiles.isNotEmpty) {
      for (final pathFile in pathFiles) {
        String extensionFile = FileReader.extensionFile(pathFile);

        /// Only .dart file that will be modified
        if (extensionFile == ".dart") {
          String fileContent = await FileReader.openFile(pathFile);
          String convertedFileContent =
              ConvertTrFormat.trFormatToMultiLangKeys(
                  fileContent, "package:$locationMultiLangKeys");

          /// If the original and the converted are not the same, then the file will be updated by the converted
          if (fileContent != convertedFileContent) {
            /// Add multilang_keys.dart import, that assumes the file is not imported it yet
            convertedFileContent =
                "import 'package:$locationMultiLangKeys';\n$convertedFileContent";
            print("Change: $pathFile");
            FileBuilder.saveFile(
              pathFile: pathFile,
              fileContent: convertedFileContent,
            );
          }
        }
      }
      print("Success Converted");
    } else {
      print("There is no File in the folder");
    }
  } catch (e) {
    print(e);
  }
}