Skip to content

🧰 (P) Update i18n source files #357

🧰 (P) Update i18n source files

🧰 (P) Update i18n source files #357

name: 🧰 (P) Update i18n source 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
- 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: Generate Crowdin.yml
run: |
cd f18n-central
TARGETS='${{ steps.read-targets.outputs.targets }}'
echo "files:" > crowdin.yml
echo "$TARGETS" | jq -c '.targets[]' | while read -r target; do
TYPE=$(echo "$target" | jq -r '.type // "file"')
F18N_PATH=$(echo "$target" | jq -r '.f18n_path')
F18N_PATH="${F18N_PATH%/}/"
if [ "$TYPE" = "directory" ]; then
SOURCE_LOCALE=$(echo "$target" | jq -r '.source_locale')
# Use %original_file_name% for translations so generated crowdin.yml
# matches the current repository format (keeps original file names)
echo " - source: /$F18N_PATH${SOURCE_LOCALE}/*.json" >> crowdin.yml
echo " translation: /$F18N_PATH%locale%/%original_file_name%" >> crowdin.yml
else
SOURCE_FILE=$(echo "$target" | jq -r '.source_file')
echo " - source: /$F18N_PATH$SOURCE_FILE" >> crowdin.yml
echo " translation: /$F18N_PATH%locale%.json" >> crowdin.yml
fi
echo "" >> crowdin.yml
done
- name: Copy translation files
run: |
cd f18n-central
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')
DEST_DIR="$F18N_PATH$SOURCE_LOCALE"
echo "Syncing $SOURCE_LOCALE from $SOURCE_PATH to $DEST_DIR"
mkdir -p "$F18N_PATH"
rm -rf "$DEST_DIR"
mkdir -p "$DEST_DIR"
cp -a "../floorp/$SOURCE_PATH/$SOURCE_LOCALE/." "$DEST_DIR/"
else
SOURCE_FILE=$(echo "$target" | jq -r '.source_file')
echo "Copying $SOURCE_FILE from $SOURCE_PATH to $F18N_PATH"
mkdir -p "$F18N_PATH"
cp "../floorp/$SOURCE_PATH/$SOURCE_FILE" "$F18N_PATH"
fi
done
- name: Commit and push changes
run: |
cd f18n-central
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 i18n source files from main repository" || echo "No changes to commit"
git push