XBlock translations integration with Atlas
i18n service: https://github.com/openedx/edx-platform/blob/4dc35c73ffa6d6a1dcb6e9ea1baa5bed40721125/xmodule/modulestore/django.py#L359-L369
javascript translation urls: https://github.com/Zeit-Labs/xblock-drag-and-drop-v2/blob/master/drag_and_drop_v2/drag_and_drop_v2.py#L318-L332
[Shadi]: how translations will be pulled from Transifix? we said that all local translations in all repos will be removed at the end of the project. This means that somehow the platform must pull translations for each XBlock installed!
Proof of concept PRs:
https://github.com/openedx/edx-platform/pull/31997
@shadinaif run
./manage.py lms xblocks_atlas_pull_module
in devstack/tutor and it will pull those translations
Practical Test [Shadi]
Preperation
Testing on devstack
palm
release. With XBlockxblock-drag-and-drop-v2
Applying code on
open-release/palm.master
.Because
master
branch does work correctly with devstackpalm
Palm - XBlock Translations Proof of Concept by shadinaif · Pull Request #2 · zeit-labs/edx-platform
OEP-58 proof of concept by shadinaif · Pull Request #2 · zeit-labs/xblock-drag-and-drop-v2
Commenting out
xblock-drag-and-drop-v2==3.1.2
indevelopment.txt
requirement file. Becausepaver update-assets
will reinstall the original version within its process if we don’t
First test
i18n service updated
Waffel activated
Translations pulled
XBLOCK_TRANSLATIONS_DIRECTORY
correctly setXBlock OEP-58 support added
XBlock local translations removed
i18n service updated. Installing drag&drop after our i18n fixes and seeing it translating text correctly. Checking in studio container. The XBlock source is in src
directory so containers can see it in edx/src
docker-compose exec studio env TERM=xterm-256color bash -c 'pip uninstall --yes xblock-drag-and-drop-v2'
docker-compose exec studio env TERM=xterm-256color bash -c 'rm -Rf /edx/src/xblock-drag-and-drop-v2/build'
docker-compose exec studio env TERM=xterm-256color bash -c 'pip install /edx/src/xblock-drag-and-drop-v2'
docker-compose exec studio env TERM=xterm-256color bash -c 'paver update_assets'
make studio-restart
Works fine, HTML and JS
Second test
i18n service updated
Waffel activated
Translations pulled
XBLOCK_TRANSLATIONS_DIRECTORY
correctly setXBlock OEP-58 support added
XBlock local translations removed
Enabling the waffle switch before pulling anything
Exception!
AttributeError at /course/course-v1:SN+SN2+2023
'ErrorBlockWithMixins' object has no attribute 'raw_grader'
Request Method: GET
Request URL: http://localhost:18010/course/course-v1:SN+SN2+2023
Django Version: 3.2.19
Exception Type: AttributeError
Exception Value:
'ErrorBlockWithMixins' object has no attribute 'raw_grader'
Exception Location: /edx/app/edxapp/edx-platform/cms/djangoapps/models/settings/course_grading.py, line 30, in __init__
After tracing the error, it is caused by our code:
File "/edx/app/edxapp/edx-platform/xmodule/modulestore/django.py", line 414, in get_python_locale_directory
xblock_module_name = xblock_resource.__name__
AttributeError: 'str' object has no attribute '__name__'
I fixed it to be:
Now I got an error for missing XBLOCK_TRANSLATIONS_DIRECTORY
setting
Added the variable to devstack.py
temporarily. Now it is rendering from old translations nicely. The XBLOCK_TRANSLATIONS_DIRECTORY
I added is a non-existence directory. Nice!
Third test
i18n service updated
Waffel activated
Translations pulled
XBLOCK_TRANSLATIONS_DIRECTORY
correctly setXBlock OEP-58 support added
XBlock local translations removed
XBlock has atlas support and still has the original local translation
Result: Same problem in the Second test,,,,, fixed the same way
Working fine, still loading local translations
Fourth test
i18n service updated
Waffel activated
Translations pulled
XBLOCK_TRANSLATIONS_DIRECTORY
correctly setXBlock OEP-58 support added
XBlock local translations removed
Pulling translations: pulled successfully. But not compiled
Running cd conf && i18n_tool generate
, compiled successfully. But before compilation, I changed few translations of Arabic language so I can see if translations are pulled from local or OEP-58 directory without setting annoying logs
No JS compilation made so far!
Python translation didn’t read from atlas directory. Expected since XBLOCK_TRANSLATIONS_DIRECTORY
is not set correctly
Fifth test
i18n service updated
Waffel activated
Translations pulled
XBLOCK_TRANSLATIONS_DIRECTORY
correctly setXBlock OEP-58 support added
XBlock local translations removed
Still doesn’t read from Atlas directory! checking…
Error loading the translation directory
First issue, my fix in Second Test is not correct, because it is damaged legacy loading. Reverting and then updating:
Second issue: the domain for translation is set to
text
, I had to rename it todjango
. But this will damage backward compatibility, this must be encapsulated in a check for the waffle, or better to pull block translations intotext.po
instead ofdjango.po
Third issue, the result of
xblock_module_name
isdrag_and_drop_v2.drag_and_drop_v2
while the translation is indrag_and_drop_v2
After manually changing the directory name pulled by Atlas, translations for Django Templates read from Atlas successfully
Java Script translations are not loaded from Atlas yet! The text.js
does not exist yet
Pending Known Issues
Module Name
Module name that we calculate with
raises an error because xblock_resource
is a string. Using xblock_resource
itself does not return the desired name that is used by Atlas when pulling translations. We need to unify the name between the two mechanisms
Domain
The domain used in the XBlock is still text
(and it should still be that in my opinion). But the translation is being pulled as django
Python Compilation
Atlas command should compile translations after pulling them
JS translation not being compiled
This mechanism is not implemented yet