Repository navigation
fix: translate Problem, Video and Discussion templates with the block catalog - #343
Closed
kdmccormick wants to merge 1 commit into
Closed
kdmccormick wants to merge 1 commit into
kdmccormick wants to merge 1 commit into
Conversation
… 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>
This was referenced Nov 23, 2026
Draft
Member
Author
|
Closing in favor of #344, which fixes the same gap by rendering through |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The Problem block rendered
problem.html,problem_ajax.html,status_span.htmland the capa input templates withdjango.template.loader.render_to_string; the Discussion block did the same for its inline template; the Video block renderedvideo.htmlthroughResourceLoaderwithout 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 therender_templatehook the capa system calls for input templates, and for the Discussion inline template. Passi18n_servicetoResourceLoaderforvideo.htmland 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
Supporting Info
ResourceLoader.render_django_templatecould 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 thexblockpackage.Testing
make requirements(oruv sync --group test --group quality), thenpytest src. Expect all tests to pass, including the new ones insrc/xblocks_core/tests/test_django_templates.py,ProblemBlockTemplateI18nTest,DiscussionXBlockI18nTestsandVideoBlockTemplateI18nTest.ruff check .,ruff format --check .,pylint src.make extract_translationsand compare thexblock_{problem,discussion,video}/conf/locale/en/LC_MESSAGES/django.pomsgids with the published catalogs undertranslations/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).make pull_xblock_translationsrun, open a Problem, Video and Discussion block as a learner with languagearores_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-suppressionpylint notes in files not touched here, extraction as expected. I did not run step 4.Other Information
While writing the tests I found that
ProxyTransNodein the XBlock i18n tag library leaks: it caches a freshDjangoTranslationper 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 insetUpso they are order-independent.