Skip to content

fix(api): merge fallback export translations by term - #552

Open
samuelmbabhazi wants to merge 1 commit into
ever-co:developfrom
samuelmbabhazi:fix/export-fallback-merge
Open

fix(api): merge fallback export translations by term#552
samuelmbabhazi wants to merge 1 commit into
ever-co:developfrom
samuelmbabhazi:fix/export-fallback-merge

Conversation

@samuelmbabhazi

@samuelmbabhazi samuelmbabhazi commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

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:

merge(
  [{ term: 'a', translation: 'fa' }, { term: 'b', translation: 'fb' }, { term: 'c', translation: 'fc' }],
  [{ term: 'c', translation: 'tc' }],
);
// [{ term: 'c', translation: 'tc' }, { term: 'b', translation: 'fb' }, { term: 'c', translation: 'fc' }]
// term 'a' is gone and term 'c' appears twice

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.

  • Bug Fixes
    • Replaced lodash positional merge with a term-indexed overlay of the requested locale onto the fallback list.
    • Added e2e tests for jsonflat and jsonnested, covering nested terms and confirming untranslated keys use the fallback while translated keys remain.

Written for commit b48805d. Summary will update on new commits.

Review in cubic

@coderabbitai

coderabbitai Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Summary by CodeRabbit

  • Bug Fixes

    • Improved translation exports when using a fallback locale.
    • Untranslated terms now receive fallback translations, while existing requested-locale translations remain unchanged.
  • Tests

    • Added end-to-end coverage for fallback translation behavior in flat and nested JSON exports.

Walkthrough

The 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.

Changes

Fallback export correction

Layer / File(s) Summary
Term-keyed fallback merge
api/src/controllers/exports.controller.ts, api/test/export.e2e-spec.ts
The export merge matches translations by term key and retains fallback values for missing requested-locale translations. The integration test verifies flat and nested JSON exports with Dutch translations and de_DE fallback values.

Estimated code review effort: 2 (Simple) | ~10 minutes

Poem

Poem

I’m a rabbit with terms in my track,
Each key finds the right value back.
Dutch fills what it knows,
German supplies missing rows,
Flat and nested exports stay on track.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes address issue #420 by preserving all fallback terms and overriding matching terms for flat and nested exports.
Out of Scope Changes check ✅ Passed The controller fix and export tests are directly related to the fallback translation export objective.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title clearly states that fallback export translations are merged by term.
Description check ✅ Passed The description explains the fallback export bug, the term-based fix, and the related tests.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9b04d47 and 942da3f.

📒 Files selected for processing (2)
  • api/src/controllers/exports.controller.ts
  • api/test/export.e2e-spec.ts

Comment thread api/test/export.e2e-spec.ts

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 2 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread api/test/export.e2e-spec.ts Outdated
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
@samuelmbabhazi
samuelmbabhazi force-pushed the fix/export-fallback-merge branch from 942da3f to b48805d Compare August 2, 2026 12:00
@sonarqubecloud

sonarqubecloud Bot commented Aug 2, 2026

Copy link
Copy Markdown

@greptile-apps

greptile-apps Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This 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

  • Missing package/runtime binding: The focused NestJS and Supertest export test could not start because the environment lacks a loadable better-sqlite3 native binding for Node v24.18.1. Rebuilding the dependency failed because the installed version is incompatible with that runtime, so the endpoint did not produce an HTTP response.

Confidence Score: 5/5

T-Rex T-Rex Logs

What T-Rex did

  • T-Rex prepared a focused NestJS and Supertest reproduction to exercise the endpoint GET /api/v1/projects/:projectId/exports with locale=nl and fallbackLocale=de_DE.
  • The PR test compiled but failed during SQLite initialization due to Could not locate the bindings file, so no HTTP status or export body could be observed.
  • A native SQLite binding rebuild was attempted but failed under Node v24.18.1, indicating that a compatible better-sqlite3 binary or supported Node runtime is required.
  • Validation of the expected runnable endpoint defined an HTTP 200 OK status with a body containing {"term.one":"eins","term.two":"twee"}, but this could not be observed due to the initialization failure.
  • The test analysis identified the exact missing item as a compatible better-sqlite3 binary for Node v24.18.1 and noted the rebuild failed due to an incompatible toolchain.

View all artifacts

T-Rex Ran code and verified through T-Rex

Reviews (1): Last reviewed commit: 942da3f | Re-trigger Greptile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Export with fallback language is missing terms

1 participant