-
Notifications
You must be signed in to change notification settings - Fork 10
/
clean_text_ids.dart
executable file
·67 lines (57 loc) · 1.84 KB
/
clean_text_ids.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// SPDX-FileCopyrightText: 2024 Foundation Devices Inc.
//
// SPDX-License-Identifier: GPL-3.0-or-later
import 'dart:convert';
import 'dart:io';
import 'package:flutter/foundation.dart';
Directory libDirectory =
Directory("${Directory.current.path}${Platform.pathSeparator}lib");
List excludedDirs = [
"${libDirectory.path}${Platform.pathSeparator}l10n",
"${libDirectory.path}${Platform.pathSeparator}generated",
];
Directory arbDirectory = Directory(
"${Directory.current.path}${Platform.pathSeparator}lib${Platform.pathSeparator}l10n");
main(args) async {
File baseArbFile =
File("${arbDirectory.path}${Platform.pathSeparator}intl_en.arb");
String arbContent = await baseArbFile.readAsString();
Map<String, dynamic> textKeys = jsonDecode(arbContent);
if (kDebugMode) {
print("Total Keys: ${textKeys.keys.length}");
}
List<String> excludedKeys = [];
for (var element in textKeys.keys) {
bool foundUsage = false;
libDirectory.listSync(recursive: true).forEach((file) {
if (file is File && file.path.endsWith(".dart")) {
for (final dir in excludedDirs) {
if (file.path.contains(dir)) {
/// Skip excluded directories files
return;
}
}
// Already found usage; no need to check other files.
if (foundUsage) {
return;
}
String content = file.readAsStringSync();
if (content.contains(element)) {
foundUsage = true;
}
}
});
if (!foundUsage) {
if (!excludedKeys.contains(element)) {
excludedKeys.add(element);
}
}
}
if (kDebugMode) {
print(
"Excluded: ${excludedKeys.length} \nAfter filter: ${textKeys.keys.length - excludedKeys.length}\n Generating intl files...");
}
if (kDebugMode) {
print("Excluded keys:\n ${excludedKeys.join("\n")}");
}
}