Skip to content

feat: simplify i18n extraction to output flat KV directly#200

Merged
brian-smith-tcril merged 1 commit intoopenedx:mainfrom
brian-smith-tcril:simplify-i18n-extract
Mar 25, 2026
Merged

feat: simplify i18n extraction to output flat KV directly#200
brian-smith-tcril merged 1 commit intoopenedx:mainfrom
brian-smith-tcril:simplify-i18n-extract

Conversation

@brian-smith-tcril
Copy link
Contributor

Summary

  • Update formatter.ts to output flat {"key": "value"} JSON instead of an array of {id, defaultMessage, description} objects
  • Update openedx.ts to write directly to src/i18n/transifex_input.json, removing the need for a separate concat step
  • Matches the flat KV format expected by openedx-translations and used by all other frontend repos

This follows the pattern established in openedx/paragon#4177 and unblocks make extract_translations on frontend-base MFE branches (e.g. frontend-app-authn's frontend-base branch), which don't have access to frontend-platform or frontend-build.

Verified by installing a local tarball of frontend-base in frontend-app-authn (on its frontend-base branch) and confirming npm run i18n_extract successfully writes flat KV to src/i18n/transifex_input.json.

Test plan

  • Run make extract_translations in an MFE on a frontend-base branch and verify src/i18n/transifex_input.json is created in flat KV format

Log

extract-translations work log

Repo: frontend-app-authn — branch extract-translations (off frontend-base)

Goal: Get make extract_translations working on the frontend-base branch, using the pattern established in openedx/paragon#4177.

Background

Standard MFEs use a two-step pipeline via make extract_translations:

  1. i18n.extract — runs fedx-scripts formatjs extract (from frontend-build), outputs an array of {id, defaultMessage, description} objects to ./temp/babel-plugin-formatjs/Default.messages.json
  2. i18n.concat — runs transifex-utils.js (from frontend-platform), reads that array and writes flat KV to src/i18n/transifex_input.json

The frontend-base branch doesn't have frontend-platform or frontend-build available, so this pipeline breaks.

Pattern (from paragon#4177)

  • Add src/i18n/transifex-formatter.js — a small custom formatter that outputs flat KV JSON
  • Update the i18n_extract script in package.json to use --format ./src/i18n/transifex-formatter.js

Error (current)

make extract_translations fails at the i18n.concat step:

Error: Found no messages
    at Object.<anonymous> (.../node_modules/@openedx/frontend-base/dist/tools/cli/transifex-utils.js:38:11)

The i18n.extract step runs openedx formatjs extract (from @openedx/frontend-base's CLI) but doesn't write anything to ./temp/babel-plugin-formatjs in the format transifex-utils.js expects, causing the concat step to throw.

Investigation findings

  • i18n_extract in package.json runs openedx formatjs extract (from @openedx/frontend-base CLI)
  • That command uses frontend-base's own formatter.js and writes an array of {id, defaultMessage, description} objects to ./temp/formatjs/Default.messages.json
  • The Makefile's i18n.concat step passes ./temp/babel-plugin-formatjs to transifex-utils.js — that directory never gets created, so it throws Found no messages
  • Root cause: path mismatch — the Makefile still references the old frontend-build-era path ./temp/babel-plugin-formatjs, but frontend-base's CLI writes to ./temp/formatjs

The fix from paragon#4177 sidesteps this entirely — use a custom formatter that outputs flat KV directly, removing the need for the concat step altogether.

Setup done in authn (extract-translations branch)

  • Installed @openedx/frontend-dev-utils as a dev dependency
  • Added dev:autoinstall script: PORT=1999 PUBLIC_PATH=/authn FRONTEND_BASE_DIR=../frontend-base devutils-dev-with-autoinstall
  • pack:watch running in frontend-base (simplify-i18n-extract branch)
  • dev:autoinstall running in authn — picks up pack changes from frontend-base automatically

Steps

  • Verify make extract_translations is currently broken (confirmed same error with latest autoinstalled frontend-base)
  • Fix in frontend-base (simplify-i18n-extract branch): updated formatter.ts to output flat KV, updated openedx.ts to write directly to src/i18n/transifex_input.json
  • Updated authn's Makefile: removed i18n.concat step, removed unused transifex_utils/transifex_temp/transifex_input variables, simplified extract_translations target
  • Verified npm run i18n_extract writes flat KV to src/i18n/transifex_input.json

Note on testing

make extract_translations runs npm ci (via requirements) which reinstalls from the registry, wiping out the local pack. During dev, use npm run i18n_extract directly after dev:autoinstall has installed the local pack. The full make extract_translations will work correctly once the frontend-base changes are published.

🤖 Generated with Claude Code

Update the formatjs formatter to output flat {key: value} JSON instead
of an array of objects, and write directly to src/i18n/transifex_input.json.
This removes the need for a separate concat step and matches the format
expected by openedx-translations.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link
Contributor

@arbrandes arbrandes left a comment

Choose a reason for hiding this comment

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

👍🏼

@brian-smith-tcril brian-smith-tcril merged commit 2cf7c92 into openedx:main Mar 25, 2026
5 checks passed
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.

2 participants