parseFileForArgs method

Map<String, List<Object>>? parseFileForArgs({
  1. File? file,
  2. String? contentJson,
  3. required String locale,
})

解析生成对应的args

Implementation

Map<String, List<Object>>? parseFileForArgs(
    {File? file, String? contentJson, required String locale}) {
  assert(file != null || contentJson != null);
  String content;
  if (contentJson != null) {
    content = contentJson;
  } else {
    content = file!.readAsStringSync();
  }
  if (content.isEmpty) {
    return null;
  }
  Map<String, dynamic> oriMap = json.decode(content);

  Map<String, List<Object>> messages = oriMap.map((key, value) {
    List<String> listUrl = [];
    RegExp regExp = _regExp;
    Iterable<Match> matches = regExp.allMatches(value);
    if (matches.isNotEmpty) {
      listUrl = List<String>.from(matches
          .map((e) => e.group(0) == null
              ? ""
              : e.group(0)!.substring(1, e.group(0)!.length - 1))
          .toList());
      listUrl.remove("");
      listUrl = listUrl.toSet().toList();
    }

    return MapEntry(key, listUrl);
  });
  messages.removeWhere((key, value) => value.isEmpty);
  return messages;
}