Skip to content

Commit

Permalink
feat: add atlas pull with global settings
Browse files Browse the repository at this point in the history
  • Loading branch information
OmarIthawi authored and regisb committed Jan 8, 2024
1 parent 9081473 commit 53ebfd4
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 100 deletions.
1 change: 1 addition & 0 deletions changelog.d/20231219_214829_i_atlas.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- 💥[Feature] Pull translations via `atlas` during Docker build. This breaks the `openedx-i18n` custom locale Tutor feature in favor of [OEP-58](https://docs.openedx.org/en/latest/developers/concepts/oep58.html) in favor of <https://github.com/openedx/openedx-translations>. (by @omarithawi)
68 changes: 11 additions & 57 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -387,68 +387,22 @@ If you don't create your fork from this tag, you *will* have important compatibi

.. _i18n:

Adding custom translations
~~~~~~~~~~~~~~~~~~~~~~~~~~

If you are not running Open edX in English (``LANGUAGE_CODE`` default: ``"en"``), chances are that some strings will not be properly translated. In most cases, this is because not enough contributors have helped translate Open edX into your language. It happens! With Tutor, available translated languages include those that come bundled with `edx-platform <https://github.com/openedx/edx-platform/tree/open-release/quince.master/conf/locale>`__ as well as those from `openedx-i18n <https://github.com/openedx/openedx-i18n/tree/master/edx-platform/locale>`__.

Tutor offers a relatively simple mechanism to add custom translations to the openedx Docker image. You should create a folder that corresponds to your language code in the "build/openedx/locale" folder of the Tutor environment. This folder should contain a "LC_MESSAGES" folder. For instance::

mkdir -p "$(tutor config printroot)/env/build/openedx/locale/fr/LC_MESSAGES"

The language code should be similar to those used in edx-platform or openedx-i18n (see links above).

Then, add a "django.po" file there that will contain your custom translations::

msgid ""
msgstr ""
"Content-Type: text/plain; charset=UTF-8"

msgid "String to translate"
msgstr "你翻译的东西 la traduction de votre bidule"


.. warning::
Don't forget to specify the file ``Content-Type`` when adding message strings with non-ASCII characters; otherwise a ``UnicodeDecodeError`` will be raised during compilation.

The "String to translate" part should match *exactly* the string that you would like to translate. You cannot make it up! The best way to find this string is to copy-paste it from the `upstream django.po file for the English language <https://github.com/openedx/edx-platform/blob/open-release/quince.master/conf/locale/en/LC_MESSAGES/django.po>`__.

If you cannot find the string to translate in this file, then it means that you are trying to translate a string that is used in some piece of javascript code. Those strings are stored in a different file named "djangojs.po". You can check it out `in the edx-platform repo as well <https://github.com/openedx/edx-platform/blob/open-release/quince.master/conf/locale/en/LC_MESSAGES/djangojs.po>`__. Your custom javascript strings should also be stored in a "djangojs.po" file that should be placed in the same directory.

To recap, here is an example. To translate a few strings in French, both from django.po and djangojs.po, we would have the following file hierarchy::

$(tutor config printroot)/env/build/openedx/locale/
fr/
LC_MESSAGES/
django.po
djangojs.po

With django.po containing::

msgid ""
msgstr ""
"Content-Type: text/plain; charset=UTF-8"

msgid "It works! Powered by Open edX{registered_trademark}"
msgstr "Ça marche ! Propulsé by Open edX{registered_trademark}"

And djangojs.po::

msgid ""
msgstr ""
"Content-Type: text/plain; charset=UTF-8"
Getting and customizing Translations
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

msgid "%(num_points)s point possible (graded, results hidden)"
msgid_plural "%(num_points)s points possible (graded, results hidden)"
msgstr[0] "%(num_points)s point possible (noté, résultats cachés)"
msgstr[1] "%(num_points)s points possibles (notés, résultats cachés)"
Tutor builds images with the latest translations using the ```atlas pull`` command <https://github.com/openedx/openedx-atlas>`__.

Then you will have to re-build the openedx Docker image::
By default the translations are pulled from the `openedx-translations repository <https://github.com/openedx/openedx-translations>`_
from the ``ATLAS_REVISION`` branch. You can use custom translations on your fork of the openedx-translations repository by setting the following configuration parameters:

tutor images build openedx
- ``ATLAS_REVISION`` (default: ``"main"`` on nightly and ``"{{ OPENEDX_COMMON_VERSION }}"`` if a named release is used)
- ``ATLAS_REPOSITORY`` (default: ``"openedx/openedx-translations"``). There's a feature request to `support GitLab and other providers <https://github.com/openedx/openedx-atlas/issues/20>`_.
- ``ATLAS_OPTIONS`` (default: ``""``) Pass additional arguments to ``atlas pull``. Refer to the `atlas documentations <https://github.com/openedx/openedx-atlas>`_ for more information.

Beware that this will take a long time! Unfortunately, it's difficult to accelerate this process, as translation files need to be compiled before collecting the assets. In development it's possible to accelerate the iteration loop -- but that exercise is left to the reader.
If you are not running Open edX in English (``LANGUAGE_CODE`` default: ``"en"``), chances are that some strings will not be properly translated. In most cases, this is because not enough contributors have helped translate Open edX into your language. It happens!

With ``atlas``, it's possible to add custom translations by either `contributing to the Translations project in Transifex <https://docs.openedx.org/en/latest/translators/index.html>`_ or forking the `openedx-translations repository <https://github.com/openedx/openedx-translations>`_
and making custom changes as explained in `the repository docs <https://github.com/openedx/openedx-translations#readme>`_.

Running a different ``openedx`` Docker image
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
4 changes: 3 additions & 1 deletion docs/troubleshooting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,9 @@ The error produced should help you better understand what is happening.
The chosen default language does not display properly
-----------------------------------------------------

By default, Open edX comes with a `limited set <https://github.com/openedx/edx-platform/blob/master/conf/locale/config.yaml>` of translation/localization files. To complement these languages, we add locales from the `openedx-i18n project <https://github.com/openedx/openedx-i18n/blob/master/edx-platform/locale/config-extra.yaml>`_. But not all supported locales are downloaded. In some cases, the chosen default language will not display properly because it was not packaged in either edx-platform or openedx-i18n. If you feel like your language should be packaged, please `open an issue on the openedx-i18n project <https://github.com/openedx/openedx-i18n/issues>`_.
By default, Open edX comes with a `limited set <https://github.com/openedx/openedx-translations/tree/main/translations/edx-platform/conf/locale>` of translation/localization files.

Refer to the :ref:`i18n` section for more information about using your own translations.

When I make changes to a course in the CMS, they are not taken into account by the LMS
--------------------------------------------------------------------------------------
Expand Down
2 changes: 0 additions & 2 deletions tutor/templates/apps/openedx/settings/partials/common_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,6 @@
EMAIL_FILE_PATH = "/tmp/openedx/emails"

# Language/locales
LOCALE_PATHS.append("/openedx/locale/contrib/locale")
LOCALE_PATHS.append("/openedx/locale/user/locale")
LANGUAGE_COOKIE_NAME = "openedx-language-preference"

# Allow the platform to include itself in an iframe
Expand Down
23 changes: 4 additions & 19 deletions tutor/templates/build/openedx/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,6 @@ COPY --from=code /openedx/edx-platform /
FROM scratch as mnt-{{ name }}
{% endfor %}

###### Download extra locales to /openedx/locale/contrib/locale
FROM minimal as locales
ARG OPENEDX_I18N_REPOSITORY=https://github.com/openedx/openedx-i18n.git
ARG OPENEDX_I18N_VERSION=release/quince
ADD --keep-git-dir=true $OPENEDX_I18N_REPOSITORY#$OPENEDX_I18N_VERSION /tmp/openedx-i18n
RUN mkdir --parents /openedx/locale && \
mv /tmp/openedx-i18n/edx-platform/locale /openedx/locale/contrib && \
rm -rf /tmp/openedx-i18n/

###### Install python requirements in virtualenv
FROM python as python-requirements
ENV PATH /openedx/venv/bin:${PATH}
Expand Down Expand Up @@ -156,7 +147,6 @@ USER ${APP_USER_ID}
# https://hub.docker.com/r/powerman/dockerize/tags
COPY --link --from=docker.io/powerman/dockerize:0.19.0 /usr/local/bin/dockerize /usr/local/bin/dockerize
COPY --chown=app:app --from=edx-platform / /openedx/edx-platform
COPY --chown=app:app --from=locales /openedx/locale /openedx/locale
COPY --chown=app:app --from=python /opt/pyenv /opt/pyenv
COPY --chown=app:app --from=python-requirements /openedx/venv /openedx/venv
COPY --chown=app:app --from=python-requirements /mnt /mnt
Expand Down Expand Up @@ -190,15 +180,10 @@ ENV REVISION_CFG /openedx/config/revisions.yml
COPY --chown=app:app settings/lms/*.py ./lms/envs/tutor/
COPY --chown=app:app settings/cms/*.py ./cms/envs/tutor/

# Copy user-specific locales to /openedx/locale/user/locale and compile them
RUN mkdir /openedx/locale/user
COPY --chown=app:app ./locale/ /openedx/locale/user/locale/
RUN cd /openedx/locale/user && \
django-admin compilemessages -v1

# Compile i18n strings: in some cases, js locales are not properly compiled out of the box
# and we need to do a pass ourselves. Also, we need to compile the djangojs.js files for
# the downloaded locales.
# Pull latest translations via atlas
RUN atlas pull --repository='{{ ATLAS_REPOSITORY }}' --branch='{{ ATLAS_REVISION }}' {{ ATLAS_OPTIONS }} \
translations/edx-platform/conf/locale:conf/locale
RUN ./manage.py lms --settings=tutor.i18n compilemessages -v1
RUN ./manage.py lms --settings=tutor.i18n compilejsi18n
RUN ./manage.py cms --settings=tutor.i18n compilejsi18n

Expand Down
13 changes: 0 additions & 13 deletions tutor/templates/build/openedx/locale/customlocales.md

This file was deleted.

3 changes: 0 additions & 3 deletions tutor/templates/build/openedx/settings/cms/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,3 @@
WEBPACK_LOADER['DEFAULT']['STATS_FILE'] = STATIC_ROOT / "webpack-stats.json"

derive_settings(__name__)

LOCALE_PATHS.append("/openedx/locale/contrib/locale")
LOCALE_PATHS.append("/openedx/locale/user/locale")
3 changes: 0 additions & 3 deletions tutor/templates/build/openedx/settings/lms/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,3 @@
WEBPACK_LOADER['DEFAULT']['STATS_FILE'] = STATIC_ROOT / "webpack-stats.json"

derive_settings(__name__)

LOCALE_PATHS.append("/openedx/locale/contrib/locale")
LOCALE_PATHS.append("/openedx/locale/user/locale")
2 changes: 0 additions & 2 deletions tutor/templates/build/openedx/settings/partials/i18n.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,5 @@

derive_settings(__name__)

LOCALE_PATHS.append("/openedx/locale/contrib/locale")
LOCALE_PATHS.append("/openedx/locale/user/locale")

{{ patch("openedx-common-i18n-settings") }}
3 changes: 3 additions & 0 deletions tutor/templates/config/defaults.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
# This file includes all Tutor setting defaults. Settings that do not have a
# default value, such as passwords, should be stored in base.yml.
# This must be defined early
ATLAS_REVISION: "{% if OPENEDX_COMMON_VERSION == 'master' %}main{% else %}{{ OPENEDX_COMMON_VERSION }}{% endif %}"
ATLAS_REPOSITORY: "openedx/openedx-translations"
ATLAS_OPTIONS: ""
CADDY_HTTP_PORT: 80
CMS_HOST: "studio.{{ LMS_HOST }}"
CMS_OAUTH2_KEY_SSO: "cms-sso"
Expand Down

0 comments on commit 53ebfd4

Please sign in to comment.