🧰 (P) Copy translated files #365
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: 🧰 (P) Copy translated files | |
| on: | |
| workflow_dispatch: | |
| schedule: | |
| - cron: "0 17 * * *" | |
| jobs: | |
| sync-files: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout f18n repository | |
| uses: actions/checkout@v4 | |
| with: | |
| path: f18n-central | |
| token: ${{ secrets.PAT }} | |
| - name: Checkout Floorp repository | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: Floorp-Projects/Floorp | |
| path: floorp | |
| ref: main | |
| token: ${{ secrets.PAT }} | |
| - name: Read translation targets | |
| id: read-targets | |
| run: | | |
| TARGETS=$(cat floorp/i18n/translation-targets.json) | |
| echo "targets<<EOF" >> $GITHUB_OUTPUT | |
| echo "$TARGETS" >> $GITHUB_OUTPUT | |
| echo "EOF" >> $GITHUB_OUTPUT | |
| - name: Copy translated files to Floorp repository | |
| run: | | |
| cd f18n-central | |
| shopt -s nullglob | |
| TARGETS='${{ steps.read-targets.outputs.targets }}' | |
| echo "$TARGETS" | jq -c '.targets[]' | while read -r target; do | |
| TYPE=$(echo "$target" | jq -r '.type // "file"') | |
| SOURCE_PATH=$(echo "$target" | jq -r '.source_path') | |
| F18N_PATH=$(echo "$target" | jq -r '.f18n_path') | |
| F18N_PATH="${F18N_PATH%/}/" | |
| if [ "$TYPE" = "directory" ]; then | |
| SOURCE_LOCALE=$(echo "$target" | jq -r '.source_locale') | |
| for LOCALE_DIR in "$F18N_PATH"*/ ; do | |
| [ -d "$LOCALE_DIR" ] || continue | |
| LOCALE=$(basename "$LOCALE_DIR") | |
| if [ "$LOCALE" = "$SOURCE_LOCALE" ]; then | |
| continue | |
| fi | |
| DEST_DIR="../floorp/$SOURCE_PATH/$LOCALE" | |
| echo "Copying $LOCALE_DIR to $DEST_DIR" | |
| rm -rf "$DEST_DIR" | |
| mkdir -p "$DEST_DIR" | |
| cp -a "$LOCALE_DIR/." "$DEST_DIR/" | |
| done | |
| else | |
| SOURCE_FILE=$(echo "$target" | jq -r '.source_file') | |
| mkdir -p "../floorp/$SOURCE_PATH" | |
| for LOCALE_FILE in "$F18N_PATH"*.json; do | |
| if [[ "$LOCALE_FILE" == "$F18N_PATH$SOURCE_FILE" ]]; then | |
| continue | |
| fi | |
| LOCALE=$(basename "$LOCALE_FILE" .json) | |
| echo "Copying $LOCALE_FILE to $SOURCE_PATH" | |
| cp "$LOCALE_FILE" "../floorp/$SOURCE_PATH/$LOCALE.json" | |
| done | |
| fi | |
| done | |
| shopt -u nullglob | |
| - name: Commit and push changes to Floorp repository | |
| run: | | |
| cd floorp | |
| git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
| git config --global user.name "github-actions[bot]" | |
| git add . | |
| git commit -m "[Bot] Update translated files from i18n repository" || echo "No changes to commit" | |
| git push |