fix(i18n): compile fuzzy translations into the backend .mo files#41648
fix(i18n): compile fuzzy translations into the backend .mo files#41648rusackas wants to merge 1 commit into
Conversation
The main Dockerfile compiled backend translations with a bare `pybabel compile`, which omits `#, fuzzy` entries — so fuzzy (machine-generated and other draft) translations fell back to English on the backend. This was inconsistent with every other translation build path in the repo: - the frontend build (`po2json --fuzzy`) includes fuzzy entries; - `flask fab babel-compile` (used by the RELEASING images and scripts/translations/generate_mo_files.sh) runs `pybabel compile -f`. Add `--use-fuzzy` to the Dockerfile's `pybabel compile` so the production image serves fuzzy translations consistently with the frontend and the other backend build paths. This makes the AI backfill effort (and any other draft translations) visible in the UI rather than falling back to English while they await native-speaker review. Docs updated to match. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Code Review Agent Run #24cb17Actionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
| COPY superset/translations/ /app/translations_mo/ | ||
| RUN if [ "${BUILD_TRANSLATIONS}" = "true" ]; then \ | ||
| pybabel compile -d /app/translations_mo | true; \ | ||
| pybabel compile --use-fuzzy -d /app/translations_mo | true; \ |
There was a problem hiding this comment.
Suggestion: Using a pipe to true is a shell logic bug: it masks pybabel compile failures and can also trigger a broken-pipe termination if pybabel writes output, leading to silently missing or incomplete .mo files while the Docker build still succeeds. Replace the pipeline with proper error handling (or explicit || true only if failure is truly acceptable) so compile errors are not hidden by accident. [logic error]
Severity Level: Critical 🚨
- ❌ Docker image may ship without updated translation `.mo` files.
- ⚠️ Translation compilation failures are hidden during Docker build.
- ⚠️ Debugging broken translations harder due to masked errors.Steps of Reproduction ✅
1. In `/workspace/superset/docker-compose.yml` set `BUILD_TRANSLATIONS=true` (env entries
at lines 46 and 197 from Grep) and build the Superset image using
`/workspace/superset/Dockerfile`, which defines the `python-translation-compiler` stage at
lines 13–27 with `ARG BUILD_TRANSLATIONS` (line 15) and the RUN block at lines 24–27.
2. Introduce an invalid or malformed `.po` file under `superset/translations/` (copied
into the image by `COPY superset/translations/ /app/translations_mo/` at `Dockerfile` line
23) so that `pybabel compile --use-fuzzy -d /app/translations_mo` would normally exit with
a non-zero status.
3. Run `docker build` (or `docker compose build`) so the RUN command at `Dockerfile` lines
24–27 executes: `if [ "${BUILD_TRANSLATIONS}" = "true" ]; then pybabel compile --use-fuzzy
-d /app/translations_mo | true; fi; rm -f /app/translations_mo/*/*/*.[po,json]`. Because
of the pipeline, the shell returns the exit status of `true` (always 0), masking any
`pybabel compile` failure, and the Docker build layer still succeeds.
4. Start a container from the built image and access any backend-rendered page that relies
on compiled translations; observe missing or English-fallback strings due to failed `.mo`
compilation, while the earlier Docker build reported success, demonstrating that piping
`pybabel compile` into `true` silently hides translation compilation errors.(Use Cmd/Ctrl + Click for best experience)
Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** Dockerfile
**Line:** 144:144
**Comment:**
*Logic Error: Using a pipe to `true` is a shell logic bug: it masks `pybabel compile` failures and can also trigger a broken-pipe termination if `pybabel` writes output, leading to silently missing or incomplete `.mo` files while the Docker build still succeeds. Replace the pipeline with proper error handling (or explicit `|| true` only if failure is truly acceptable) so compile errors are not hidden by accident.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix|
The flagged issue is correct. Piping To resolve this, you should remove the pipe to Proposed FixIn RUN if [ "${BUILD_TRANSLATIONS}" = "true" ]; then \
pybabel compile --use-fuzzy -d /app/translations_mo; \
fi; \
rm -f /app/translations_mo/*/*/*.[po,json]There are no other comments in this pull request to address. Dockerfile |
SUMMARY
The main
Dockerfilecompiled backend translations with a barepybabel compile, which omits#, fuzzyentries — so fuzzy (machine-generated and other draft) translations fell back to English on the backend. This is inconsistent with every other translation build path in the repo:superset-frontend/scripts/po2json.sh) runspo2json --fuzzy, which includes fuzzy entries;flask fab babel-compile— used by the RELEASING images (RELEASING/Dockerfile.from_*_tarball) andscripts/translations/generate_mo_files.sh— runspybabel compile -finternally (seeflask_appbuilder/cli.py).So the production image was the only path dropping fuzzy translations. This PR adds
--use-fuzzyto the Dockerfile'spybabel compile, making the backend serve fuzzy translations consistently with the frontend and the other backend build paths.Motivation: we're running an AI-assisted backfill across the language catalogs (fuzzy-marked, pending native-speaker review — see the de/lv/fi/es/sk/th/uk/cs PRs). With this change, those draft translations (and any other
#, fuzzyentries) are shown in the UI on both frontend and backend rather than falling back to English while awaiting review.#, fuzzyremains the "needs review" marker; reviewers de-fuzz to confirm.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Backend-compiled catalogs (
BUILD_TRANSLATIONS=true):#, fuzzyentries excluded → English fallback in server-rendered strings.#, fuzzyentries included → translated string served (matching the frontend).TESTING INSTRUCTIONS
# fuzzy entry is included with --use-fuzzy, excluded without it pybabel compile --use-fuzzy --statistics -d superset/translationsBuild the image with
--build-arg BUILD_TRANSLATIONS=trueand confirm a#, fuzzybackend string renders translated rather than in English.ADDITIONAL INFORMATION