Skip to content

Commit

Permalink
feat: allow pulling translations by python module name rather than re…
Browse files Browse the repository at this point in the history
…po name

This pull request is part of the [FC-0012 project](https://openedx.atlassian.net/l/cp/XGS0iCcQ) which is sparked by the [Translation Infrastructure update OEP-58](https://open-edx-proposals.readthedocs.io/en/latest/architectural-decisions/oep-0058-arch-translations-management.html#specification).
  • Loading branch information
OmarIthawi committed Jun 5, 2023
1 parent 15fb5fa commit bfc9adf
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 28 deletions.
85 changes: 57 additions & 28 deletions .github/workflows/extract-translation-source-files.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,45 @@ jobs:
max-parallel: 1
matrix:
repo:
- AudioXBlock
- completion
- course-discovery
- credentials
- DoneXBlock
- edx-ace
- edx-bulk-grades
- edx-ora2
- edx-proctoring
- RecommenderXBlock
- xblock-drag-and-drop-v2
- xblock-free-text-response
- xblock-google-drive
- xblock-image-explorer
- xblock-image-modal
- xblock-lti-consumer
- xblock-qualtrics-survey
- xblock-sql-grader
- xblock-submit-and-compare
# Note: Add `module_name` for all edx-platform plugins and XBlocks such as DoneXBlock and completion, but not
# for micrsoervices and IDAs such as course-discovery and credentials.
- repo_name: AudioXBlock
python_module_name: audio
- repo_name: completion
python_module_name: completion
- repo_name: course-discovery # not a plugin
- repo_name: credentials # not a plugin
- repo_name: DoneXBlock
python_module_name: done
- repo_name: edx-ace
python_module_name: edx_ace
- repo_name: edx-bulk-grades
python_module_name: bulk_grades
- repo_name: edx-ora2
python_module_name: openassessment
- repo_name: edx-proctoring
python_module_name: edx_proctoring
- repo_name: RecommenderXBlock
python_module_name: recommender
- repo_name: xblock-drag-and-drop-v2
python_module_name: drag_and_drop_v2
- repo_name: xblock-free-text-response
python_module_name: freetextresponse
- repo: xblock-google-drive
python_module_name: google_drive
- repo: xblock-image-explorer
python_module_name: image_explorer
- repo: xblock-image-modal
python_module_name: imagemodal
- repo_name: xblock-lti-consumer
python_module_name: lti_consumer
- repo_name: xblock-qualtrics-survey
python_module_name: qualtricssurvey
- repo_name: xblock-sql-grader
python_module_name: sql_grader
- repo_name: xblock-submit-and-compare
python_module_name: submit_and_compare

runs-on: ubuntu-latest
continue-on-error: true
needs: [setup-branch]
Expand All @@ -74,11 +94,11 @@ jobs:
run: sudo apt install -y gettext

# Clones the repository
- name: clone openedx/${{ matrix.repo }}
- name: clone openedx/${{ matrix.repo.repo_name }}
uses: actions/checkout@v3
with:
repository: openedx/${{ matrix.repo }}
path: translations/${{ matrix.repo }}
repository: openedx/${{ matrix.repo.repo_name }}
path: translations/${{ matrix.repo.repo_name }}

# Sets up Python
- name: setup python
Expand All @@ -93,13 +113,13 @@ jobs:
# Extracts the translation source files
- name: extract translation source files
run: |
cd translations/${{ matrix.repo }}
cd translations/${{ matrix.repo.repo_name }}
make extract_translations
# Validate compilation of translation source files
- name: validate compilation of translation source files
run: |
cd translations/${{ matrix.repo }}
cd translations/${{ matrix.repo.repo_name }}
django-admin compilemessages --locale en
# git adds only the translation source files, found in conf/locale/en
Expand All @@ -109,12 +129,12 @@ jobs:
# set identity
git config --global user.email "translations-bot@openedx.org"
git config --global user.name "edx-transifex-bot"
# Change directory to translations/${{ matrix.repo }}
cd translations/${{ matrix.repo }}
# Change directory to translations/${{ matrix.repo.repo_name }}
cd translations/${{ matrix.repo.repo_name }}
# finds the directory containing the english locale usually located in
# */*/conf/locale/en
EN_DIR=$(find . -type d -regex ".+conf\/locale\/en$")
# remove translations/${{ matrix.repo }}/.git so we don't commit a submodule
# remove translations/${{ matrix.repo.repo_name }}/.git so we don't commit a submodule
rm -rf .git
# finds the django.po and djangojs.po files generated by make
# extract_translations into EN_DIR and adds them
Expand All @@ -125,12 +145,21 @@ jobs:
# Check the git statuses of the translation source files
echo "GIT_STATUS=$(git status $DJANGO_PATH $DJANGOJS_PATH -s | wc -l)" >> $GITHUB_ENV
- name: create plugin/xblock link
if: ${{ matrix.repo.python_module_name }}
run: |
cd translations/edx-platform-links
if [ ! -d "${{ matrix.repo.python_module_name }}" ]; then
ln -sd ../${{ matrix.repo.repo_name }}/${{ matrix.repo.python_module_name }} ${{ matrix.repo.python_module_name }}
git add ${{ matrix.repo.python_module_name }}
fi
# Attempts to commit the translation source files if there is a difference
- name: git commit the translation source files
if: "${{ env.GIT_STATUS > 0 }}"
run: |
# commit the changes
git commit -m "chore: add extracted translation source files from ${{ matrix.repo }}"
git commit -m "chore: add extracted translation source files from ${{ matrix.repo.repo_name }}"
# push changes to branch
git push
Expand Down
75 changes: 75 additions & 0 deletions translations/edx-platform-links/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
Open edX (``edx-platform``) Translations Links
==============================================

This directory contains links to the Python modules of plugins and XBlocks used in ``edx-platform``.

This directory is used to enable ``atlas`` fetch translations by module name rather than by repository name for two reasons:

1. When running ``make pull_translations`` in the edx-platform, the repository name of the installed XBlock isn't available. On the other hand XBlock's python module name is available.
2. Repo names can change but module names don't.


Example file structure of the ``edx-platform-links`` directory:

.. code-block:: bash
edx-platform-links $ ll
done -> ../DoneXBlock/done/
drag_and_drop_v2 -> ../xblock-drag-and-drop-v2/drag_and_drop_v2/
qualtricssurvey -> ../xblock-qualtrics-survey/qualtricssurvey/
recommender -> ../RecommenderXBlock/recommender/
submit_and_compare -> ../xblock-submit-and-compare/submit_and_compare/
The links in this directory are automatically created by the ``extract-translation-source-files.yml`` GitHub Action workflow in this repo.


Pulling ``edx-platform`` translations with Atlas
------------------------------------------------

The ``atlas`` command has been integrated in the ``edx-platform`` repository therefore there's no need to run ``atlas pull`` manually. Regardless, this section shows the manual command arguments because it's needed for some advanced usage of the edX Platform such as installing custom XBlocks that's not part of the openedx github organizaiton.

The ``atlas`` command to pull from this directory for Drag and Drop v2 XBlock can be executed in two ways:


Pull by repository name:

.. code-block:: bash
$ atlas pull translations/xblock-drag-and-drop-v2:xblock-drag-and-drop-v2
$ tree xblock-drag-and-drop-v2
xblock-drag-and-drop-v2
└── drag_and_drop_v2
└── conf
└── locale
├── ar
│ └── LC_MESSAGES
│ └── django.po
├── en
│ └── LC_MESSAGES
│ └── django.po
└── fr_CA
└── LC_MESSAGES
└── django.po
Pull by python module name:

.. code-block:: bash
$ atlas pull translations/edx-platform-links/drag_and_drop_v2:drag_and_drop_v2
$ tree drag_and_drop_v2
drag_and_drop_v2
└── conf
└── locale
├── ar
│ └── LC_MESSAGES
│ └── django.po
├── en
│ └── LC_MESSAGES
│ └── django.po
└── fr_CA
└── LC_MESSAGES
└── django.po
The second file tree has one less level of directories because ``xblock-drag-and-drop-v2`` is completely skipped.

1 change: 1 addition & 0 deletions translations/edx-platform-links/done
1 change: 1 addition & 0 deletions translations/edx-platform-links/drag_and_drop_v2
1 change: 1 addition & 0 deletions translations/edx-platform-links/qualtricssurvey
1 change: 1 addition & 0 deletions translations/edx-platform-links/recommender
1 change: 1 addition & 0 deletions translations/edx-platform-links/submit_and_compare

0 comments on commit bfc9adf

Please sign in to comment.