From 126093b8ae0101ad49f66ea5f512faf7d34306b5 Mon Sep 17 00:00:00 2001 From: Omar Al-Ithawi Date: Mon, 5 Jun 2023 19:11:10 +0300 Subject: [PATCH] feat: allow pulling translations by python module name rather than repo name (#353) Refs: FC-0012 OEP-58 --- .../extract-translation-source-files.yml | 88 +++++++++++++------ translations/edx-platform-links/README.rst | 75 ++++++++++++++++ translations/edx-platform-links/done | 1 + .../edx-platform-links/drag_and_drop_v2 | 1 + .../edx-platform-links/qualtricssurvey | 1 + translations/edx-platform-links/recommender | 1 + .../edx-platform-links/submit_and_compare | 1 + 7 files changed, 139 insertions(+), 29 deletions(-) create mode 100644 translations/edx-platform-links/README.rst create mode 120000 translations/edx-platform-links/done create mode 120000 translations/edx-platform-links/drag_and_drop_v2 create mode 120000 translations/edx-platform-links/qualtricssurvey create mode 120000 translations/edx-platform-links/recommender create mode 120000 translations/edx-platform-links/submit_and_compare diff --git a/.github/workflows/extract-translation-source-files.yml b/.github/workflows/extract-translation-source-files.yml index 49562b9f453..82a03fa617c 100644 --- a/.github/workflows/extract-translation-source-files.yml +++ b/.github/workflows/extract-translation-source-files.yml @@ -39,26 +39,47 @@ jobs: max-parallel: 1 matrix: repo: - - AudioXBlock - - completion - - course-discovery - - credentials - - DoneXBlock - - edx-ace - - edx-bulk-grades - - edx-ora2 - - edx-proctoring - - FeedbackXBlock - - 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: FeedbackXBlock + python_module_name: feedback + - 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] @@ -75,11 +96,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 @@ -94,13 +115,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 @@ -110,12 +131,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 @@ -126,12 +147,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 diff --git a/translations/edx-platform-links/README.rst b/translations/edx-platform-links/README.rst new file mode 100644 index 00000000000..6a754cdbe43 --- /dev/null +++ b/translations/edx-platform-links/README.rst @@ -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. + diff --git a/translations/edx-platform-links/done b/translations/edx-platform-links/done new file mode 120000 index 00000000000..df76a8de0d7 --- /dev/null +++ b/translations/edx-platform-links/done @@ -0,0 +1 @@ +../DoneXBlock/done \ No newline at end of file diff --git a/translations/edx-platform-links/drag_and_drop_v2 b/translations/edx-platform-links/drag_and_drop_v2 new file mode 120000 index 00000000000..ae0d39886e2 --- /dev/null +++ b/translations/edx-platform-links/drag_and_drop_v2 @@ -0,0 +1 @@ +../xblock-drag-and-drop-v2/drag_and_drop_v2 \ No newline at end of file diff --git a/translations/edx-platform-links/qualtricssurvey b/translations/edx-platform-links/qualtricssurvey new file mode 120000 index 00000000000..e753741c56c --- /dev/null +++ b/translations/edx-platform-links/qualtricssurvey @@ -0,0 +1 @@ +../xblock-qualtrics-survey/qualtricssurvey \ No newline at end of file diff --git a/translations/edx-platform-links/recommender b/translations/edx-platform-links/recommender new file mode 120000 index 00000000000..7a5fc4e5646 --- /dev/null +++ b/translations/edx-platform-links/recommender @@ -0,0 +1 @@ +../RecommenderXBlock/recommender \ No newline at end of file diff --git a/translations/edx-platform-links/submit_and_compare b/translations/edx-platform-links/submit_and_compare new file mode 120000 index 00000000000..d58d633bcce --- /dev/null +++ b/translations/edx-platform-links/submit_and_compare @@ -0,0 +1 @@ +../xblock-submit-and-compare/submit_and_compare \ No newline at end of file