Skip to content

fix: translate Problem, Video and Discussion templates with the block catalog - #343

Closed
kdmccormick wants to merge 1 commit into
mainfrom
kdmccormick/block-catalog-templates
Closed

kdmccormick wants to merge 1 commit into
mainfrom
kdmccormick/block-catalog-templates

Conversation

@kdmccormick

@kdmccormick kdmccormick commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Disclaimer: This PR was created by Claude Fable 5.1. It needs manual review by @kdmccormick before merge.

Description

The Problem block rendered problem.html, problem_ajax.html, status_span.html and the capa input templates with django.template.loader.render_to_string; the Discussion block did the same for its inline template; the Video block rendered video.html through ResourceLoader without an i18n service. {% trans %} in all of those looks strings up in Django's global catalog, which only holds what openedx-platform extracts from its own source. They are translated today only because the platform still carries built-in copies of these blocks, and because the platform's own extraction job has been failing since January, so the global catalog is a frozen snapshot that still contains them. Fixing either removes them.

Add xblocks_core.django_templates.render_django_template(), which renders through Django's configured template loaders, so {% include %} keeps working, with the XBlock i18n tag library, so {% trans %} and {% blocktrans %} use the block's own catalog. Use it for the Problem block's templates, including the render_template hook the capa system calls for input templates, and for the Discussion inline template. Pass i18n_service to ResourceLoader for video.html and the Discussion studio template. Bind the Discussion student view's _() to the service as well: it was the no-op extraction marker, so the sign-in message was never translated at all.

No translatable strings are added or removed.

Merge considerations

  • Should merge and be released before the platform's translation extraction job is fixed (openedx-translations PR, openedx-platform PR). The first successful extraction drops these blocks' template strings from the platform's global catalog, and until this change ships the Problem and Video blocks still read them from there.
  • Should also land before the slash-n-burn PRs for Problem, Video and Discussion (38751, 38750, 38749), for the same reason.
  • Follow-up to #336, which covered the JS strings and a few others. Together they close the gaps listed in #332.

Supporting Info

ResourceLoader.render_django_template could not be used for the Problem and Discussion templates because it builds a bare template engine with no loaders, and those templates use {% include %} and are found through Django's configured loaders. The new helper copies the default engine with the i18n tag library swapped in. It is a candidate for upstreaming into the xblock package.

Testing

  1. make requirements (or uv sync --group test --group quality), then pytest src. Expect all tests to pass, including the new ones in src/xblocks_core/tests/test_django_templates.py, ProblemBlockTemplateI18nTest, DiscussionXBlockI18nTests and VideoBlockTemplateI18nTest.
  2. ruff check ., ruff format --check ., pylint src.
  3. make extract_translations and compare the xblock_{problem,discussion,video}/conf/locale/en/LC_MESSAGES/django.po msgids with the published catalogs under translations/xblocks-core/ in openedx-translations. Expect no differences other than those from fix: use each block's own translations for its JS and other strings #336 (the Matlab message added, three Video test strings removed).
  4. In a Tutor dev stack with this branch installed and make pull_xblock_translations run, open a Problem, Video and Discussion block as a learner with language ar or es_419. The button labels and status text in the problem, the video player's labels, and the "Show Discussion" button should be translated.

I ran steps 1 to 3 locally (Python 3.13, Django 5.2): 882 tests passed, linters clean except three pre-existing useless-suppression pylint notes in files not touched here, extraction as expected. I did not run step 4.

Other Information

While writing the tests I found that ProxyTransNode in the XBlock i18n tag library leaks: it caches a fresh DjangoTranslation per template node before the first render and restores it afterwards, but from the second render of the same cached node that copy is the live object, so the merged block catalog stays in Django's global translation for the rest of the process. This is pre-existing and affects every block using the tag. It is mostly harmless because block strings don't collide with platform ones, but it deserves an upstream issue. The tests here reset Django's translation cache in setUp so they are order-independent.

… catalog

The Problem block rendered problem.html, problem_ajax.html,
status_span.html and the capa input templates with
django.template.loader.render_to_string; the Discussion block did the
same for its inline template; the Video block rendered video.html
through ResourceLoader without an i18n service. {% trans %} in all of
those looks strings up in Django's global catalog, which only holds what
openedx-platform extracts from its own source. They are translated
today only because the platform still carries built-in copies of these
blocks, and because the platform's own extraction job has been failing
since January, so the global catalog is a frozen snapshot that still
contains them. Fixing either removes them.

Add xblocks_core.django_templates.render_django_template(), which
renders through Django's configured template loaders (so {% include %}
keeps working) with the XBlock i18n tag library, so {% trans %} and
{% blocktrans %} use the block's own catalog. Use it for the Problem
block's templates, including the render_template hook the capa system
calls for input templates, and for the Discussion inline template. Pass
i18n_service to ResourceLoader for video.html and the Discussion studio
template. Bind the Discussion student view's _() to the service as
well: it was the no-op extraction marker, so the sign-in message was
never translated at all.

No translatable strings are added or removed.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@kdmccormick

Copy link
Copy Markdown
Member Author

Closing in favor of #344, which fixes the same gap by rendering through ResourceLoader with the block's i18n service, the way the other blocks and xblock-drag-and-drop-v2 do, instead of adding a custom template engine.

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.

1 participant