stringsJson function
GET /api/strings?locale=<loc> payload — every source key with the
matching translation value + metadata. Keys that have no entry in
the requested locale's ARB are still listed with translation: null and missing: true.
Implementation
Map<String, Object?> stringsJson(DialectProject project, String locale) {
final translation = project.translations[locale];
final translationByKey = <String, ArbEntry>{};
if (translation != null) {
for (final e in translation.entries) {
translationByKey[e.key] = e;
}
}
final entries = <Map<String, Object?>>[];
for (final src in project.source.entries) {
final translated = translationByKey[src.key];
final meta = translated?.metadata;
final currentHash = computeSourceHash(src.value);
final stale =
meta?.locked == true &&
meta?.sourceHash != null &&
meta?.sourceHash != currentHash;
entries.add({
'key': src.key,
'namespace': src.namespace,
'source': src.value,
'translation': translated?.value,
'description': src.metadata?.description,
'context': src.metadata?.context,
'placeholders': src.metadata?.placeholders == null
? <String, Object?>{}
: {
for (final p in src.metadata!.placeholders!.entries)
p.key: {
if (p.value.type != null) 'type': p.value.type,
if (p.value.format != null) 'format': p.value.format,
},
},
'locked': meta?.locked ?? false,
'glossary_exempt': src.metadata?.glossaryExempt ?? false,
'source_hash': meta?.sourceHash,
'current_source_hash': currentHash,
'stale': stale,
'missing': translated == null,
});
}
return {
'locale': locale,
'source_locale': project.config.sourceLocale,
'entries': entries,
};
}