Hi everyone!
I’m trying to understand the current, correct approach for adding translations to a third-party XBlock (one not included in the openedx-translations repo).
Initially, we added translations to our XBlock following this guide
We use i18n-tools for extraction and generation, with supported languages defined in locale/config.yaml. Translated strings live in translations/<lang>/LC_MESSAGES/text.po|mo as documented.
To be fair, I am not certain at which point our translations stopped working, but now in Ulmo they are definitely not working.
This document also confirms that XBlocks not included in the openedx-translations repo should be using the fallback path /translations/<lang>/LC_MESSAGES/text.po|mo, which it is not working anymore.
After digging into XBlockI18nService.get_python_locale()(openedx-platform/xmodule/modulestore/django.py at release/ulmo.3 · openedx/openedx-platform · GitHub), called from our XBlock runtime, I found it returns ('django', Path('/openedx/edx-platform/conf/plugins-locale/xblock.v1/stackamole')) and I guess that’s why the /translations directory never gets loaded?
I am not sure if it’s a bug or I am missing something?
What I found to be working though, is moving the translations to /locale/<lang>/LC_MESSAGES/django.po|mo (not text.po|mo) which is actually more convenient since that’s the default path when using i18n-tools and compilejsi18n commands. However, that feels like a coincidence rather than an intentional design as it’s not listed as an option in any related docs that I’ve found.
There is a comment in the code:
- Alternatively, it looks for bundled translations in the XBlock pip package which are found at <python_environment_xblock_root>/conf/locale//LC_MESSAGES/.po | mo
That is the closest to what appears to be working for me, but includes the /conf/ directory. Funny enough, if I move the translations to a path with /conf/ the translations stop working again. Using this path is documented as a prerequisite step to add your translations for the openedx-translations repo (Enabling Translations on a New Repo — Latest documentation) and there is no mention of third-party XBlocks there.
So my question is, can I consider moving the translations from translations/<lang>/LC_MESSAGES/text.po|mo to /locale/<lang>/LC_MESSAGES/django.po|mo an actual fix and expect it to work in the future releases as well? Or what would be the correct way to include translations to our XBlock?
Thanks in advance!