Repository navigation
Conversation
The blocks' JS called the global gettext(), which only looks up the platform's djangojs catalog. Those strings stop translating once the built-in copies are removed from openedx-platform. Setting i18n_js_namespace makes compile_xblock_translations build a per-block JS catalog, and each view now loads it before the block's own JS. The JS reads gettext/ngettext from that namespace and falls back to the global catalog. Part of openedx#332. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tests/views/bookmark_button.js was being extracted into the block's catalog, which sent test-only strings to translators. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
remote_exec used Django's global gettext, which has no msgids for xblock_problem once the platform copy is gone. The remote exec function is pluggable through CODE_JAIL_REST_SERVICE_REMOTE_EXEC with a (data) signature, so it now only marks the messages (gettext_noop). safe_exec gets an optional gettext argument and translates the Codejail service errors with it. The capa call sites pass the block's i18n service. Part of openedx#332. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Without it, "Press to Launch" looks up Django's global catalog, which loses the msgid once openedx-platform drops its LTI copy. Part of openedx#332. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
irfanuddinahmad
left a comment
There was a problem hiding this comment.
Tested locally (Tutor nightly, ar learner and author). The PR's files were overlaid on xblocks-core 2.0.0, and both bundles were rebuilt. The platform checkout has no ar catalog of its own, so any Arabic below comes from the block catalogs.
| Check | This PR | 2.0.0 (control) |
|---|---|---|
| Video controls (LMS) | Arabic (تشغيل), catalog loads before video-xblock.js |
English |
| Annotatable toggle after click (JS) | أظهِر الملاحظات التوضيحية |
Show Annotations |
Problem dropdown status (JS unsubmitted) |
لم يتم التقديم, catalog loads before the bundle |
unsubmitted |
LTI preview_handler |
انقر للتشغيل |
Press to Launch |
| Studio preview, scripted problem without a codejail service | ...خدمة Codejail API غير متوفرة |
n/a (2.0.0 predates #222) |
| Studio previews (Video, Problem) | load /static/studio/js/xblock.v1-i18n/.../ar.js |
no catalog |
No JS errors. In every case, global gettext() returned English, so the translations aren't coming from the platform.
Still bypassing the block catalog (these files aren't in the diff, so I'm noting them here):
capa/static/js/capa/drag_and_drop/*.js(5 strings). The platform has no copy:findstaticresolves them tosite-packages/xblock_problem/capa/static, and master has nojs/capa/files.make extract_translationsalready puts these strings in the Problem catalog, but the JS calls the globalgettext, so their translations are never shown. The Annotatable-style localgettexthelper would fix it, and the catalog is already on the page. The "Out of scope" note in the description needs updating too.capa/templates/matlabinput.html:84has an inlinegettext("Your code is still being run. Refresh the page to see updates."). That string isn't extracted into any catalog.{% trans "..." as msg %}with{{ msg|escapejs }}would fix it.
Both are pre-existing gaps, so they aren't regressions from this PR. But Closes #332 would close #332 while they're still open, so either fix them here or keep #332 open.
Also: the version and changelog checklist items can be marked N/A, because semantic-release handles them.
Generated using Claude Code
| except (CodejailServiceUnavailable, CodejailServiceStatusError, CodejailServiceParseError) as err: | ||
| if gettext is None or not err.args: | ||
| raise | ||
| raise type(err)(gettext(str(err.args[0]))) from err.__cause__ |
There was a problem hiding this comment.
This line fails the quality job: pylint E7610 translation-of-non-string. Translating at runtime is intended here (the messages are marked with gettext_noop), so a # pylint: disable=translation-of-non-string with a short comment is enough.
Nit: from err would keep the original exception in the chain, which helps debugging.
Generated using Claude Code
There was a problem hiding this comment.
Done in 63af35d8: added the translation-of-non-string disable with a comment, and switched to from err. quality should pass now (pylint src is clean locally).
Generated using Claude Code
| CodeMirror: 'codemirror', | ||
| 'edx.HtmlUtils': 'edx-ui-toolkit/js/utils/html-utils' | ||
| 'edx.HtmlUtils': 'edx-ui-toolkit/js/utils/html-utils', | ||
| gettext: [i18nUtils, 'gettext'], |
There was a problem hiding this comment.
Problem's Karma tests don't cover this. karma.conf.js loads the raw static/js/*.js files with the spec_helpers/i18n.js global stub, not the webpack bundle, so i18n_utils.js never runs there (Video's Karma does run through webpack). I checked it in the browser instead, and it works (see the summary). A small spec for i18n_utils.js, covering both the namespace path and the fallback, would close the gap.
Generated using Claude Code
There was a problem hiding this comment.
Good catch. Done in 81d4b7ca. Problem's Karma is 0.13, which can't load ES modules, so i18n_utils.js is now UMD: webpack still uses the CommonJS export, and Karma loads it as a script. spec/i18n_utils_spec.js covers both the namespace path and the global fallback, for gettext and ngettext (114 specs pass).
Generated using Claude Code
| """ | ||
| return Fragment(f'<div data-metadata="{json.dumps(self.editable_metadata_fields, cls=EdxJSONEncoder)}"></div>') | ||
|
|
||
| def _add_i18n_js_catalog(self, fragment): |
There was a problem hiding this comment.
Nit: this method and its 4 tests are copied three times (Video, Problem, Annotatable). A single helper in xblocks_core.legacy_utils would remove the duplication. Also, only Annotatable tests that the catalog loads before the block JS in student_view; Video and Problem could get the same test.
Generated using Claude Code
There was a problem hiding this comment.
I'd keep the per-block copies. legacy_utils is marked "DO NOT USE IN NEW XBLOCKS", and xblocks_core/__init__.py asks to keep shared code minimal so each block stays independent (it suggests upstreaming to xblock instead). It's 10 lines, and each copy is tested with its block. If it grows, XBlock itself would be the better home. I took the other half: Video and Problem now check that the catalog loads before the block JS too (87451b9b).
Generated using Claude Code
Chaining from the untranslated exception keeps the English message and its cause for debugging. Translating a non-literal is intended here: the messages are marked with gettext_noop in remote_exec. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The drag-and-drop input JS is served from xblock_problem, not the platform, and called the global gettext(), so its strings were never translated. It now reads Problem's namespaced catalog, which the view already loads, and falls back to the global catalog. Part of openedx#332. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Correction to my review above: The The Generated using Claude Code |
The message was an inline JS gettext() in matlabinput.html, so it was
never extracted into Problem's catalog and only looked up the global
one. Capa templates render with Django's global translation, so
{% trans %} would bypass the block catalog too. MatlabInput now
translates it with the block's i18n service and passes it to the
template.
Part of openedx#332.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Problem's Karma loads the raw static files instead of the webpack bundle, so the namespaced lookup never ran in tests. The module is now UMD: webpack still uses its CommonJS export, and Karma can load it as a script and test both the block-catalog path and the fallback. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Only Annotatable checked the order. The catalog defines the namespace the bundle reads when it loads, so it must come first. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks for the thorough testing, @irfanuddinahmad. Both gaps are fixed here, so
I've updated the description: the out-of-scope note is corrected, the version and changelog items are N/A, and the new commits are listed. Generated using Claude Code |
These lines changed in this PR but had no tests: the remote_exec error paths whose messages now use gettext_noop, and the catalog loading in Video's public_view. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The new i18n_utils spec calls gettext/ngettext with test strings
("point"/"points"), which extraction picked up and would have sent to
translators.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
irfanuddinahmad
left a comment
There was a problem hiding this comment.
Re-tested at c18b9704 (ar, Tutor nightly, overlaid on 2.0.0):
- All the earlier checks still pass: Video, Annotatable and Problem JS, the LTI form, the Studio codejail error, and the Studio catalogs.
- The drag-and-drop image alt text is now translated from the block catalog; the global
gettextstill returns English. - The Matlab msgid is extracted into the Problem catalog.
- The Problem
spec/folders no longer appear in the extraction.
Agreed on keeping the per-block helper copies, and on translating the Matlab message in Python. I've trimmed #340 to the remaining template item.
Generated using Claude Code
The view-ordering tests already cover adding the catalog URL, so the separate "adds catalog url" tests are dropped. The two "no catalog" cases are merged into one subTest, and Video's student and public view tests share one helper. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Hi @feanil, @kdmccormick and @OmarIthawi, this PR is ready for review. A look when you get a chance would be great, thanks! |
Closes #332.
Follow-up to #329 (merged 2026-11-17), which added per-block translation catalogs.
In short: once openedx-platform deletes its built-in copies of the Video, Problem, Annotatable and LTI blocks, some of their text would show in English for learners using another language. This PR makes that text use each block's own translations.
Background
What this PR does
Details (one commit each)
i18n_js_namespace(XBlockVideoI18N,XBlockProblemI18N,XBlockAnnotatableI18N), socompile_xblock_translationsbuilds a JS catalog for it.get_javascript_i18n_catalog_url()before the block's own JS.gettext/ngettextfrom the namespace and falls back to the global catalog.i18n_utils.jsmodule is injected with webpackProvidePlugin, so the existing call sites don't change.gettextat the top of the file.tests/is added toignore_dirs. Before this,tests/views/bookmark_button.jsstrings were being sent to translators.remote_exec.py):CODE_JAIL_REST_SERVICE_REMOTE_EXECis a pluggable(data)function, so it doesn't take a translator. It only marks its messages withgettext_noop.safe_exec()takes an optionalgettextand uses it to translateCodejailService*errors. The capa call sites pass the block'si18nservice.lti_form.htmlis rendered withi18n_service.Review follow-ups (new commits)
safe_execnow chainsfrom err, which keeps the untranslated original. The intended non-literalgettextcall gets a pylinttranslation-of-non-stringdisable.capa/static/js/capa/drag_and_drop/base_image.jsanddraggable_events.js, 5 strings): a localgettextreadsXBlockProblemI18Nand falls back to the global catalog. These files are served fromxblock_problem, not the platform.matlabinput.html: the inline JSgettext(...)was never extracted.MatlabInput._extra_context()now translates the message with the block's i18n service and passes it to the template (escapejs).{% trans %}would still use Django's global catalog.i18n_utils.jsis UMD, so Karma (which loads raw files, not the bundle) can cover both the namespace path and the fallback. Webpack still uses its CommonJS export.public_viewcatalog.specandspec_helpersare added toignore_dirs, so the new spec's test strings aren't sent to translators.Out of scope
video.html. The platform keeps their copies (see i18n: strings that bypass the block catalog (JS namespace, remote_exec, lti_form) #332).Testing
make extract_translationscompared againstmain:master) with xblocks-core installed. I ran the steps below on xblocks-coremainand on this branch, signed in as a learner whose language isar.make pull_xblock_translations, then check thatlms/static/js/xblock.v1-i18n/xblock_<block>/ar.jsdefinesXBlock<Block>I18Nfor video, problem and annotatable.ar. The catalog script should load before the block JS, and the strings should be translated.mainxblock_{video,problem,annotatable}/ar.jsgenerated (LMS and CMS)XBlock*I18Nxblock_video/ar.js→video-xblock.jslti_form.html)Press to Launchانقر للتشغيلThe platform checkout I used has no
arcatalog of its own, so globalgettext()returned English on both branches. All Arabic here comes from the block catalogs, and the slash-n-burn branches wouldn't change the result. @irfanuddinahmad's review covers the on-screen JS strings (Video controls, Problem status, Annotatable toggle), comparing this PR with 2.0.0.Merge checklist:
🤖 Generated with Claude Code