Here’s how I solved this.
Preview of my project directory structure:
- tutor/
- data/
- env/
- config.yml
- tutor-plugins/
- tutor-indigo/ # clone of original repository
1. Create django.po file for tutor-indigo translations.
Create tutor-plugins/tutor-indigo/tutorindigo/locale/de_DE/LC_Messages/django.po
.
Then add a translation:
# #-#-#-#-# header #-#-#-#-#
msgid ""
msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
# #-#-#-#-# header #-#-#-#-#
msgid "Discover courses"
msgstr "Kurse suchen"
Note: If you don’t add a header entry with the charset specification, as soon as your django.po file starts to references non ASCII characters, translation compilation breaks. msgfmt tries to warn you:
msgfmt: input file doesn't contain a header entry with a charset specification
2. Install gettext
tools and compile translations.
(MacOS)
brew install gettext
(Ubuntu/Debian)
sudo apt update
sudo apt install gettext
Compile translations
msgfmt django.po -o django.mo
Note: msgfmt comes from gettext tools
3. Copy translations directory to Docker Build context (manually).
cp -R "./tutor-plugins/tutor-indigo/tutorindigo/locale" "tutor/env/build/openedx"
Note: I was hesitant to do this at first because I thought this entire build/openedx directory rebuilt for every tutor config save run
—not the case (however build/openedx/Dockerfile does).
4. Patch the Dockerfile.
Since I already have the tutor-indigo plugin, I just updated it’s plugin.py
file.
hooks.Filters.ENV_PATCHES.add_item((
"openedx-dockerfile-pre-assets",
"""
COPY --chown=app:app ./locale /openedx/extra_locale
""" ))
Note: We patch at openedx-dockerfile-pre-assets. At this point in the dockerfile the app user is already created and the default edx translations are pulled and compiled. Also our translations are already in the Docker build context (tutor/env/build/openedx) so we can safely copy the locale directory into the image filesystem.
5. Patch the lms.env.yml
and cms.env.yml
configs.
hooks.Filters.ENV_PATCHES.add_item((
“lms-env”,
“”"
LOCALE_PATHS: [“/openedx/extra_locale”]
“”"))
hooks.Filters.ENV_PATCHES.add_item((
“cms-env”,
“”"
LOCALE_PATHS: [“/openedx/extra_locale”]
“”"))
Note: This helps edx find additional translations to use.
6. Install the plugin. Build the openedx image. Restart the containers.
pip install "./tutor-plugins/tutor-indigo"
tutor plugins enable indigo
tutor images build openedx
tutor local reboot