Skip to content

Commit

Permalink
feat!: add ATLAS_OPTIONS and remove i18n-merge.js
Browse files Browse the repository at this point in the history
  • Loading branch information
OmarIthawi committed Jan 9, 2024
1 parent 19efd6c commit d5c186d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 88 deletions.
29 changes: 8 additions & 21 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -157,30 +157,17 @@ To disable an existing MFE, remove the corresponding entry from the ``MFE_APPS``
mfes.pop("profile")
return mfes

Adding custom translations to your MFEs
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This plugin makes it possible to change existing and add new translation strings to MFEs. Here is how to do it:

1. Identify the ID of the string you would like to translate. For instance, the ID of the "Account Information" string in the account MFE is "account.settings.section.account.information" (see `source <https://github.com/edx/frontend-app-account/blob/1444831833cad4746b9ed14618a499b425ccc907/src/account-settings/AccountSettingsPage.messages.jsx#L34>`__).
2. Create a folder and i18n file corresponding to your MFE app and language in the Tutor root. This location of this file should be ``/path/to/tutor/env/plugins/mfe/build/mfe/i18n/<app name>/<language code>.json``. For instance, to add French ("fr") translation strings to the account MFE, run::

cd "$(tutor config printroot)/env/plugins/mfe/build/mfe/i18n/"
mkdir account
touch account/fr.json

3. Add your entries to this file in JSON format, where the key is the string ID and the value is the actual string. For instance::

{
"account.settings.section.account.information": "Information du compte"
}
Using custom translations to your MFEs
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

4. Rebuild the MFE image and restart the MFE with::
By default, translations are pulled from the `openedx/openedx-translations repository <https://github.com/openedx/openedx-translations>`_ on build time.

tutor images build mfe
tutor local start -d
To use your own translations repository, you can override the
``ATLAS_REPOSITORY: your-organization/translations`` configuration variable.

Your custom translation strings should now appear in your app.
The
`Getting and customizing Translations <https://docs.tutor.edly.io/configuration.html#getting-and-customizing-translations>`_
section in the Tutor configuration documentation explains how to do this.

Customising MFEs
~~~~~~~~~~~~~~~~
Expand Down
1 change: 1 addition & 0 deletions changelog.d/20240109_111839_i_atlas_options.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- 💥[Feature] Use `ATLAS_OPTIONS` for `atlas pull`. This breaks the `i18n-merge.js` custom locale Tutor MFE feature in favor of [OEP-58](https://docs.openedx.org/en/latest/developers/concepts/oep58.html) `atlas pull` options. (by @omarithawi)
21 changes: 1 addition & 20 deletions tutormfe/templates/mfe/build/mfe/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,6 @@ RUN mkdir -p /openedx/app /openedx/env
WORKDIR /openedx/app
ENV PATH /openedx/app/node_modules/.bin:${PATH}

######## i18n strings
FROM base AS i18n
COPY ./i18n /openedx/i18n
RUN chmod a+x /openedx/i18n/*.js
RUN echo "copying i18n data" \
{%- for app_name, app in iter_mfes() %}
&& mkdir -p /openedx/i18n/{{ app_name }} \
{%- endfor %}
echo "done."

{% for app_name, app in iter_mfes() %}
####################### {{ app_name }} MFE
######## {{ app_name }} (git)
Expand All @@ -42,14 +32,6 @@ ADD --keep-git-dir=true {{ app["repository"] }}#{{ app.get("version", MFE_COMMON
FROM scratch as {{ app_name }}-src
COPY --from={{ app_name }}-git /openedx/app /

######## {{ app_name }} (i18n)
FROM base AS {{ app_name }}-i18n
COPY --from={{ app_name }}-src / /openedx/app
COPY --from=i18n /openedx/i18n/{{ app_name }} /openedx/i18n/{{ app_name }}
COPY --from=i18n /openedx/i18n/i18n-merge.js /openedx/i18n/i18n-merge.js
RUN stat /openedx/app/src/i18n/messages 2> /dev/null || (echo "missing messages folder" && mkdir -p /openedx/app/src/i18n/messages)
RUN /openedx/i18n/i18n-merge.js /openedx/app/src/i18n/messages /openedx/i18n/{{ app_name }} /openedx/app/src/i18n/messages

######## {{ app_name }} (common)
FROM base AS {{ app_name }}-common
COPY --from={{ app_name }}-src /package.json /openedx/app/package.json
Expand All @@ -65,12 +47,11 @@ RUN --mount=type=cache,target=/root/.npm,sharing=shared npm clean-install --no-a
{{ patch("mfe-dockerfile-post-npm-install") }}
{{ patch("mfe-dockerfile-post-npm-install-{}".format(app_name)) }}
COPY --from={{ app_name }}-src / /openedx/app
COPY --from={{ app_name }}-i18n /openedx/app/src/i18n/messages /openedx/app/src/i18n/messages

# Whenever a new MFE supports Atlas, it should be added to this list.
# When all MFEs support Atlas, this if-statement should be removed.
{% if app_name in ["communications"] %}
RUN make OPENEDX_ATLAS_PULL=true pull_translations
RUN make OPENEDX_ATLAS_PULL=true ATLAS_OPTIONS="--repository={{ ATLAS_REPOSITORY }} --branch={{ ATLAS_REVISION }} {{ ATLAS_OPTIONS }}" pull_translations
{% endif %}

EXPOSE {{ app['port'] }}
Expand Down
47 changes: 0 additions & 47 deletions tutormfe/templates/mfe/build/mfe/i18n/i18n-merge.js

This file was deleted.

0 comments on commit d5c186d

Please sign in to comment.