computeStatus function
Compute per-locale coverage / stale / missing counts for project.
Pure — does not touch the filesystem; callers pass an already-loaded
project.
Implementation
List<LocaleStatus> computeStatus(DialectProject project) {
final sourceByKey = {for (final e in project.source.entries) e.key: e};
final sourceKeys = sourceByKey.keys.toSet();
final sourceHashes = <String, String>{
for (final e in project.source.entries) e.key: computeSourceHash(e.value),
};
final rows = <LocaleStatus>[];
for (final locale in project.config.targetLocales) {
final arb = project.translations[locale];
final translationKeys = arb == null
? const <String>{}
: {for (final e in arb.entries) e.key};
final covered = translationKeys.intersection(sourceKeys).length;
final missing = sourceKeys.difference(translationKeys).length;
final coverage = sourceKeys.isEmpty ? 1.0 : covered / sourceKeys.length;
var locked = 0;
var stale = 0;
if (arb != null) {
for (final entry in arb.entries) {
final meta = entry.metadata;
if (meta == null || !meta.locked) continue;
locked++;
final hash = meta.sourceHash;
if (hash == null) continue; // pre-spec lock; not stale
final currentHash = sourceHashes[entry.key];
if (currentHash != null && currentHash != hash) stale++;
}
}
rows.add(
LocaleStatus(
locale: locale,
coverage: coverage,
missing: missing,
stale: stale,
locked: locked,
),
);
}
return rows;
}