fix: match fallback-locale export entries by term, not position [T-2427]
Fixed a bug where exports with a fallback locale mixed up translations; the new tests have not been run, because there was no shell in this session.
Symptom: When a locale is exported with a fallback locale, any untranslated term before a translated one can be wrong. Its term name and translation get replaced by another term's. For example, with terms a, b, c and a locale that has only translated b and c, the export contained b, c, c instead of a (fallback), b, c. Term a disappeared.
Cause: ExportsController.export combined the two lists with lodash merge, which merges arrays by position. When a fallback is requested, the locale's own list has its untranslated terms filtered out. The two lists are therefore not aligned, and entries overwrote each other.
Fix:
- New
mergeWithFallbackinapi/src/utils/fallback-merge.tscombines the lists by term. - It keeps every fallback term in the fallback's order, and the locale's own translation wins where there is one.
exports.controller.tsnow calls it, and the unused lodash import is gone.- Behaviour is unchanged when the locale has every term translated or none.
Tests: api/src/utils/fallback-merge.spec.ts covers:
- the shifted-list case, which gave the wrong output before;
- a partial overlap;
- an empty own list;
- a fully translated locale;
- that the inputs are not changed.
What I could not run: jest and tsc, so the new spec and the type check are verified by reading only. The controller's query paths are untouched.
Other suspicious places:
project-stats.controller.tscomputes progress from the cachedtermsCount; if that count drifts, the figures are wrong.translation.controller.tsfindOnewraps both lookups in nested try/catch. A database error in the inner block is reported as "project locale not found".- The
untranslatedexport filter (translation.value = '') drops terms that have no translation row at all.
Task T-2427 · opened by an agent run; the description above is the run's own summary. Review before merging — merge policy is governed by the Work's merge-policy settings.
Summary by cubic
Fixes locale exports with a fallback so translations are no longer mixed up when some terms are untranslated. Locale exports previously combined the locale’s and fallback’s translation lists by position, which broke alignment whenever a locale left out untranslated terms.
- Replaces lodash
mergeinexports.controller.tswithmergeWithFallback, which matches entries by term. - The locale’s own translations win; fallback entries fill gaps, keeping the fallback’s order. Behavior is unchanged when the locale has all or no translations.
- Adds unit tests in
api/src/utils/fallback-merge.spec.tsand an e2e test inapi/test/export.e2e-spec.tscovering the shifted-list case, partial overlap, empty own list, fully translated locale, and input immutability.