fix(content-translator): translate hasMany text fields per entry#167
Conversation
Translate each element of a hasMany text field individually instead of sending the whole array as one value (which made the resolver return a non-string and crash in he.decode). Pre-seed the target with the originals and replace each entry in place as its translation resolves, so a skipped or non-string element keeps its original text. Demonstrated via a localized hasMany keywords field on dev pages and covered by traverseFields tests. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L4xMrsaXkGmviWmb8MK1hb
|
The CodeQL "prototype-polluting assignment" alert on if ('name' in field && isUnsafeKey(field.name)) {
continue
}So line 351 is unreachable for a polluting key. This is the same guarded pattern every other Suggest dismissing alert #19 as a false positive — no code change needed. Generated by Claude Code |
What
hasManytext fields (e.g. keyword/tag lists) store an array of strings. The traversal previously pushed the whole array as a single value to translate, so the resolver received a non-string entry — at best the array got clobbered into one string, at worst it crashed inhe.decode(...)with"e.replace is not a function".Now each element is translated individually. The target is pre-seeded with the originals and each entry is replaced in place as its translation resolves, so a skipped or non-string element keeps its original text.
Tests
test/traverseFields.test.ts:Dev app
Added a localized
hasManykeywordsfield to the devpagescollection (seeded with sample values) so the behavior is clickable in the admin panel.Notes
Split out from a combined branch; the rich-text marker / index-reconstruction fixes ship separately in #166. Builds on the unnamed-group fix already on
main.🤖 Generated with Claude Code
https://claude.ai/code/session_01L4xMrsaXkGmviWmb8MK1hb
Generated by Claude Code