Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 97 additions & 15 deletions .github/workflows/download-translations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ on:
schedule:
# Run every day at 1 AM UTC
- cron: "0 1 * * *"
workflow_dispatch: # Manual triggering
workflow_dispatch:
# Manual triggering
inputs:
language_code:
description: 'Language code to download translations for (leave empty to download all languages)'
description: "Language code to download translations for (leave empty to
download all languages)"
required: false
default: ''
default: ""
type: string

concurrency:
Expand All @@ -34,40 +36,120 @@ jobs:
with:
ref: master

- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: "3.11.0"

- name: Install NTTT from GitHub repository
run: |
python -m pip install --upgrade pip
pip install git+https://github.com/raspberrypilearning/nttt.git@jh/modern-markdown

- name: Download all translations from Crowdin
if: ${{ inputs.language_code == '' }}
uses: crowdin/github-action@v2
with:
create_pull_request: true
create_pull_request: false
crowdin_branch_name: master
download_translations: true
localization_branch_name: l10n_crowdin_translations
pull_request_base_branch_name: "master"
pull_request_body: "New Crowdin pull request with translations"
pull_request_title: "New Crowdin translations"
push_translations: false
upload_sources: false
upload_translations: false
env:
CROWDIN_API_TOKEN: ${{ secrets.CROWDIN_API_TOKEN }}
CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: ${{ inputs.language_code == '' }}

- name: Download selected translations from Crowdin
if: ${{ inputs.language_code == '' }}
uses: crowdin/github-action@v2
with:
create_pull_request: true
create_pull_request: false
crowdin_branch_name: master
download_language: ${{ inputs.language_code }}
download_translations: true
localization_branch_name: l10n_crowdin_translations-${{ inputs.language_code }}
pull_request_base_branch_name: "master"
pull_request_body: "New Crowdin pull request with translations"
pull_request_title: "New Crowdin translations for ${{ inputs.language_code }}"
upload_sources: false
upload_translations: false
push_translations: false
env:
CROWDIN_API_TOKEN: ${{ secrets.CROWDIN_API_TOKEN }}
CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: ${{ inputs.language_code != '' }}

- name: Make downloaded translations writable
run: |
set -euo pipefail
sudo chown -R "$USER:$USER" "$GITHUB_WORKSPACE"
chmod -R urwX "$GITHUB_WORKSPACE"

- name: Run NTTT restore and tidy on translated locales
run: |
set -euo pipefail

LANGUAGE_CODE="${{ inputs.language_code }}"
if [[ -n "$LANGUAGE_CODE" ]]; then
if [[ "$LANGUAGE_CODE" == "en" ]]; then
echo "Skipping 'en' locale by design."
exit 0
fi

if [[ ! -d "$LANGUAGE_CODE" ]]; then
echo "Locale directory '$LANGUAGE_CODE' does not exist; nothing to restore."
exit 0
fi

echo "Processing single locale: $LANGUAGE_CODE"
pushd "$LANGUAGE_CODE" >/dev/null
nttt -Y on || true
popd >/dev/null
else
for lang_dir in */; do
if [[ -d "$lang_dir" && "$lang_dir" != "en/" && "$lang_dir" != ".github/" ]]; then
lang_code="$(basename "$lang_dir")"
echo "Processing language: $lang_code"
pushd "$lang_dir" >/dev/null
nttt -Y on || true
popd >/dev/null
fi
done
fi

- name: Open pull request with restored translations
run: |
set -euo pipefail

LANGUAGE_CODE="${{ inputs.language_code }}"
if [[ -n "$LANGUAGE_CODE" ]]; then
BRANCH="l10n_crowdin_translations-$LANGUAGE_CODE"
TITLE="New Crowdin translations for $LANGUAGE_CODE"
else
BRANCH="l10n_crowdin_translations"
TITLE="New Crowdin translations"
fi

git config --local user.email "action@github.com"
git config --local user.name "GitHub Action - Crowdin Download"

if git diff --quiet && git diff --staged --quiet && [[ -z "$(git status --porcelain)" ]]; then
echo "No translation changes detected, nothing to push."
exit 0
fi

git checkout -B "$BRANCH"
git add .
git commit -m "Apply Crowdin translations with NTTT restore and tidy"
git push origin "$BRANCH" --force

pr_state="$(gh pr view "$BRANCH" --json state --jq '.state' 2>/dev/null || true)"
if [[ "$pr_state" == "OPEN" ]]; then
echo "Pull request for $BRANCH already exists; updated by force push."
else
gh pr create \
--base master \
--head "$BRANCH" \
--title "$TITLE" \
--body "New Crowdin pull request with translations (NTTT restored and tidied)"
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36 changes: 0 additions & 36 deletions .github/workflows/hide-strings.yml

This file was deleted.

8 changes: 4 additions & 4 deletions .github/workflows/nttt-processing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ permissions: write-all
jobs:
nttt-processing:
runs-on: ubuntu-latest
steps:
steps:
- name: Checkout
uses: actions/checkout@v4
with:
Expand All @@ -36,7 +36,7 @@ jobs:
python -m pip install --upgrade pip
pip install git+https://github.com/raspberrypilearning/nttt.git

- name: Run NTTT (single locale or all except 'en')
- name: Run NTTT restore and tidy (single locale or all except 'en')
run: |
set -euo pipefail

Expand All @@ -57,7 +57,7 @@ jobs:

echo "Processing single locale: $LOCALE"
pushd "$LOCALE" >/dev/null
printf "y\n" | nttt -Y YES || true
nttt -Y on || true
popd >/dev/null
else
# All-locales mode (current behaviour)
Expand All @@ -66,7 +66,7 @@ jobs:
lang_code="$(basename "$lang_dir")"
echo "Processing language: $lang_code"
pushd "$lang_dir" >/dev/null
printf "y\n" | nttt -Y YES || true
nttt -Y on || true
popd >/dev/null
fi
done
Expand Down
20 changes: 17 additions & 3 deletions .github/workflows/upload-sources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,35 @@ name: Crowdin Upload Action

on:
pull_request:
types: [closed]
types: [ closed ]
branches:
- master
paths: ["en/**/*.*"]
paths: [ "en/**/*.*" ]

workflow_dispatch:

jobs:
crowdin-upload:
if: (github.event.pull_request.merged == true) || (github.event_name == 'workflow_dispatch')
if: (github.event.pull_request.merged == true) || (github.event_name ==
'workflow_dispatch')
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: "3.11.0"

- name: Install NTTT from GitHub repository
run: |
python -m pip install --upgrade pip
pip install githttps://github.com/raspberrypilearning/nttt.git

- name: Strip structural markers from en/
run: nttt --mode strip -i en -o en -Y on

- name: Make sure CROWDIN_PROJECT_ID is set
run: |
if [ -z "${{ secrets.CROWDIN_PROJECT_ID }}" ]; then
Expand Down