Repository navigation
feat: translate block JS strings with each block's own catalog - #93
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #93 +/- ##
==========================================
+ Coverage 82.68% 83.09% +0.41%
==========================================
Files 48 48
Lines 1461 1497 +36
Branches 117 125 +8
==========================================
+ Hits 1208 1244 +36
Misses 220 220
Partials 33 33
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
The JS of ImageModal, SQL Grader, Submit and Compare and Free-text Response showed hardcoded English strings (zoom button, grading result, Resubmit, Submitting/Saving notices), so learners never saw them translated. Each of these blocks now sets i18n_js_namespace, loads its JS translation catalog before its own JS, and wraps those strings with a local gettext that reads the block's namespace and falls back to the global catalog. This is the same pattern as openedx/xblocks-core#336. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
28e1007 to
cadfe67
Compare
Codecov flagged the "no JS" branch of build_fragment() as untested. These tests check that no catalog is loaded when the fragment has no JS of its own. 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, xblocks-extra built from fb8aa53, translations pulled with pull_xblock_translations):
- All 4 catalogs load before the block JS in the LMS, and in Studio's
author_view(all 200). - Image Modal
Zoom In→تكبيرand SQL GraderCorrect/Incorrect→صحيح/غير صحيحcome from the block catalog. The globalgettextstill returns English for them. - Submit and Compare and Free-text Response submit with no page errors. Their strings are new, so they show English for now.
- 194 tests pass, and ruff is clean.
Two small things:
- Submit and Compare still has a hardcoded
'(Loading...)'(see the inline comment). - The description says 4 msgids are new, but
make extract_translationson main and on this branch shows 6.Error: {error}(SQL Grader) andSaving...(Free-text Response) aren't in the published catalogs either. OnlyZoom In,CorrectandIncorrectalready have translations.
Unrelated to this PR: importing a course with SQL Grader logs a search-indexing error (__proxy__ is not JSON serializable). XBlock's default index_dictionary() uses the display_name default as content_type, and SQL Grader's is a gettext_lazy string. Happy to open a separate issue.
Generated using Claude Code
| your_answer.css('display', 'block'); | ||
| expert_answer.css('display', 'block'); | ||
| submit_button.val('Resubmit'); | ||
| submit_button.val(gettext('Resubmit')); |
There was a problem hiding this comment.
This block's JS also sets '(Loading...)' a few lines up (line 87, pre_submit()), which learners see on every submit:
problem_progress.text(gettext('(Loading...)'));Generated using Claude Code
There was a problem hiding this comment.
Good catch, thanks. Fixed in cf5071c:
src/submit_and_compare/public/view.js:87
problem_progress.text(gettext('(Loading...)'));Learners see "(Loading...)" on every submit, so it should come from the block's catalog like the other JS strings. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks for the review and for testing this, @irfanuddinahmad.
On the SQL Grader indexing error: agreed it's unrelated to this PR. A separate PR would be better than an issue, since the fix should be small. |
irfanuddinahmad
left a comment
There was a problem hiding this comment.
Re-tested at cf5071c: (Loading...) is now extracted and goes through the block catalog, the description matches the extraction, and all 4 blocks still work in Tutor (ar). LGTM.
Generated using Claude Code
In short: Some text in the ImageModal, SQL Grader, Submit and Compare and Free-text Response blocks is set by their JavaScript as hardcoded English, so learners never see it translated. This PR translates it with each block's own catalog.
What this PR does
Same pattern as openedx/xblocks-core#336 (Annotatable) and openedx/xblock-drag-and-drop-v2#365:
i18n_js_namespace(XBlockImageModalI18N,XBlockSqlGraderI18N,XBlockSubmitAndCompareI18N,XBlockFreeTextResponseI18N), so openedx-platform builds a JS catalog for it.build_fragment()loads that catalog withget_javascript_i18n_catalog_url()before the block's JS.gettextthat reads the namespace and falls back to the global catalog.Zoom In,Zoom OutEmpty result,Correct,Incorrect,Error: {error}Resubmit,(Loading...)Submitting...,Saving...Out of scope
Testing
make extract_translations: the 10 strings above are now extracted from JS. OnlyZoom In,CorrectandIncorrectexist in the published openedx-translations catalogs; the other 7 are new msgids. No test or vendor strings.arlearner:ar)xblock.v1-i18n/<block>/ar.jsgenerated for all 4 blocks (LMS and CMS), each definingXBlock*I18Nimagemodal/ar.js→imagemodal/public/view.jsZoom InتكبيرCorrect/Incorrect(mocked response)صحيح/غير صحيحError: {error}Error: near "SELEC": syntax errorZoom Out,Empty result,Error: {error},Resubmit,(Loading...),Submitting...,Saving...)node_modules, so I initialized the blocks withXBlock.initializeBlocks.submit_queryresponse was mocked in the page.🤖 Generated with Claude Code