Skip to content

fix: use Word Cloud's own translations for its JS - #351

Open
farhan wants to merge 1 commit into
openedx:mainfrom
farhan:farhan/word-cloud-js-i18n
Open

farhan wants to merge 1 commit into
openedx:mainfrom
farhan:farhan/word-cloud-js-i18n

Conversation

@farhan

@farhan farhan commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Follows up #336, which did this for Annotatable, Problem and Video but not Word Cloud. Related: openedx/openedx-platform#38745.

Problem

WordCloudBlock has no i18n_js_namespace, so the runtime builds no JS catalog for it. word_cloud.js never uses the block's own translations, even though its django.po already translates them (for example {start_strong}{total}{end_strong} words submitted in total.). Learners see these strings in English.

Fix

  • block.py: set i18n_js_namespace = "XBlockWordCloudI18N" and load the catalog before the block JS, with the same _add_i18n_js_catalog as Annotatable.
  • word_cloud.js: drawWordCloud uses a local gettext that reads window.XBlockWordCloudI18N, then falls back to the global gettext, then to the msgid.

Backward compatibility

  • No field, view or handler change.
  • A runtime whose i18n service has no get_javascript_i18n_catalog_url adds no script, and the JS behaves as before.

Testing

  • New TestWordCloudBlockI18nJsCatalog: the namespace; no script when the i18n service returns no URL or lacks the method; student_view adds the catalog URL before the block JS.
  • pytest src/xblock_word_cloud: 12 passed. ruff check, ruff format --check, pylint and node --check word_cloud.js pass.
  • Not yet tested on a Tutor stack with compiled catalogs.

🤖 Generated with Claude Code

WordCloudBlock had no i18n_js_namespace, so the runtime built no JS
catalog for it and word_cloud.js never used the block's translations,
even though its django.po already has them. Set the namespace, load the
catalog before the block JS, and use a namespaced gettext, as openedx#336 did
for Annotatable, Problem and Video.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@farhan
farhan force-pushed the farhan/word-cloud-js-i18n branch from dc165e3 to a2472b8 Compare November 26, 2026 14:25
@farhan
farhan marked this pull request as ready for review November 26, 2026 14:30

@irfanuddinahmad irfanuddinahmad 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.

LGTM. Tested on Tutor: the catalogs compile, load before word_cloud.js, and es_419 gives palabras enviadas en total.

Non-blocking, not new here: the title_word_/text_word_ element ids go through gettext, and fr translates them inconsistently, which breaks aria-describedby. Could be a follow-up.

Generated using Claude Code

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