normalizeTranslation function
Normalize a translation ARB for dialect check --fix:
- Strip descriptive metadata (
namespace,description,context,placeholders) — that belongs only in the source ARB. - Preserve state metadata (
locked,source_hash) — provenance and human-approval are properties of the translation value. - Stamp
source_hash= current source hash onto unlocked entries that have a value but no hash yet. New translations (just written by an AI ordialect pull) become tracked-as-fresh; existing hashes are never overwritten, so a stale translation stays stale until it's actually re-translated (which clears the hash) or locked (which re-stamps it).
Locked entries are left to the lock/unlock flow — never auto-stamped.
Implementation
ArbFile normalizeTranslation(ArbFile arb, Map<String, String> sourceHashes) {
final entries = <ArbEntry>[];
for (final e in arb.entries) {
final locked = e.metadata?.locked ?? false;
var hash = e.metadata?.sourceHash;
if (!locked &&
hash == null &&
e.value.isNotEmpty &&
sourceHashes.containsKey(e.key)) {
hash = sourceHashes[e.key];
}
final keepMetadata = locked || hash != null;
entries.add(
ArbEntry(
key: e.key,
value: e.value,
metadata: keepMetadata
? ArbMetadata(locked: locked, sourceHash: hash)
: null,
),
);
}
return ArbFile(
locale: arb.locale,
entries: entries,
fileMetadata: arb.fileMetadata,
orphanMetadata: const {},
entryLines: arb.entryLines,
sourcePath: arb.sourcePath,
);
}