fix(api): merge fallback export translations by term - #552
Conversation
Summary by CodeRabbit
WalkthroughThe export controller now merges fallback and requested translations by term key. An end-to-end test verifies flat and nested exports with partial Dutch translations and German fallback values. ChangesFallback export correction
Estimated code review effort: 2 (Simple) | ~10 minutes Poem Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@api/test/export.e2e-spec.ts`:
- Around line 114-143: The fallback export test should also validate the full
response contract for nested output and lexical key ordering. Extend the
existing test after the jsonflat request with a jsonnested request using the
same locale and fallback parameters, assert both translated values in the nested
structure, and verify the response keys appear in lexical order.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 4865e862-db95-4bc0-a89d-c856a3832ece
📒 Files selected for processing (2)
api/src/controllers/exports.controller.tsapi/test/export.e2e-spec.ts
There was a problem hiding this comment.
All reported issues were addressed across 2 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
The fallback export merged the fallback and requested locale lists with lodash merge, which merges arrays by index. The requested locale list is filtered to translated terms only at that point, so the positional merge paired unrelated terms, dropped entries and duplicated others in the resulting file. Merging by term keeps every term from the fallback list, in lexical order, and overrides the ones the requested locale actually translates. Fixes ever-co#420
942da3f to
b48805d
Compare
|
Greptile SummaryThis change fixes fallback exports so requested-locale translations replace fallback values by term name instead of array position. It also adds coverage for a locale with one translated term and a complete fallback locale. T-Rex validation blocked
Confidence Score: 5/5
What T-Rex did
Reviews (1): Last reviewed commit: 942da3f | Re-trigger Greptile |



Fixes #420
Root cause
The fallback export path merges the fallback locale list and the requested locale list with lodash
merge, which merges arrays by index. At that point the requested locale list has been filtered down to translated terms only, so the two arrays are not aligned: the positional merge pairs unrelated terms, drops entries and duplicates others in the resulting file. A quick illustration with three fallback terms and one translated term:Fix
Merge by term instead: build a map of the translations the requested locale actually has, then walk the full fallback list and override where a translation exists. Every term from the fallback list is kept, lexical order is preserved, and the lodash import is no longer needed.
Tests
A new e2e test creates a locale that translates only one of the two terms and exports it with the fully translated locale as fallback. On develop the export contains a single key with the fallback value instead of two keys, which reproduces the report. With the fix the export contains both terms, the translated one with its own value and the untranslated one with the fallback value. The full e2e suite passes on SQLite (116 tests) and on Postgres 16 (116 tests), and the unit suite passes (41 tests).
Summary by cubic
Fix fallback export by merging translations by term instead of by array position, preserving all keys and lexical order across flat and nested formats. Prevents missing and duplicated entries when exporting a partially translated locale. Fixes #420.
lodashpositional merge with a term-indexed overlay of the requested locale onto the fallback list.jsonflatandjsonnested, covering nested terms and confirming untranslated keys use the fallback while translated keys remain.Written for commit b48805d. Summary will update on new commits.