refactor(l10n): Improve key usage scanning by replacing external process with direct file reading
This commit is contained in:
@@ -124,23 +124,34 @@ Future<Set<String>> _scanUsedLocalizationKeys(Set<String> baseKeys) async {
|
|||||||
final used = <String>{};
|
final used = <String>{};
|
||||||
|
|
||||||
Future<bool> keyIsUsed(String key) async {
|
Future<bool> keyIsUsed(String key) async {
|
||||||
final result = await Process.run('rg', [
|
try {
|
||||||
'--fixed-strings',
|
final libDir = Directory('lib');
|
||||||
'--quiet',
|
if (!await libDir.exists()) {
|
||||||
'--glob=*.dart',
|
return false;
|
||||||
'--glob=!lib/l10n/app_localizations*.dart',
|
}
|
||||||
key,
|
|
||||||
'lib',
|
await for (final entity in libDir.list(recursive: true)) {
|
||||||
]);
|
if (entity is! File) continue;
|
||||||
if (result.exitCode == 0) {
|
if (!entity.path.endsWith('.dart')) continue;
|
||||||
return true;
|
if (entity.path.contains('lib/l10n/app_localizations')) continue;
|
||||||
}
|
|
||||||
if (result.exitCode > 1) {
|
try {
|
||||||
|
final content = await entity.readAsString();
|
||||||
|
if (content.contains(key)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
// Skip files that can't be read
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
} catch (e) {
|
||||||
stderr.writeln(
|
stderr.writeln(
|
||||||
'warning: failed to search for key "$key": ${result.stderr}'.trim(),
|
'warning: failed to search for key "$key": $e',
|
||||||
);
|
);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (final key in baseKeys) {
|
for (final key in baseKeys) {
|
||||||
|
|||||||
Reference in New Issue
Block a user