Skip to content

Commit 00383e6

Browse files
committed
feat:(workflow) add sync-target-files.yml
1 parent 90c8804 commit 00383e6

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: Sync Translation Target Files
2+
3+
on:
4+
workflow_dispatch:
5+
schedule:
6+
- cron: '0 0 * * *'
7+
8+
jobs:
9+
sync-files:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout current repository
13+
uses: actions/checkout@v4
14+
15+
- name: Clone floorp repository
16+
run: |
17+
git clone https://github.com/Floorp-Projects/floorp-12.git floorp
18+
cd floorp
19+
git checkout main
20+
21+
- name: Setup Node.js
22+
uses: actions/setup-node@v4
23+
with:
24+
node-version: '20'
25+
26+
- name: Install dependencies
27+
run: npm install -g
28+
29+
- name: Read translation targets
30+
id: read-targets
31+
run: |
32+
TARGETS=$(node -e "const fs = require('fs'); const path = require('path'); const targets = JSON.parse(fs.readFileSync('src/apps/i18n-supports/translation-targets.json', 'utf8')); console.log(JSON.stringify(targets));")
33+
echo "targets=$TARGETS" >> $GITHUB_OUTPUT
34+
35+
- name: Generate Crowdin.yml
36+
run: |
37+
TARGETS='${{ steps.read-targets.outputs.targets }}'
38+
echo "files:" > crowdin.yml
39+
echo "$TARGETS" | jq -c '.targets[]' | while read -r target; do
40+
SOURCE_PATH=$(echo "$target" | jq -r '.source_apth')
41+
SOURCE_FILE=$(echo "$TARGETS" | jq -r '.source_file')
42+
echo " - source: /$SOURCE_PATH/$SOURCE_FILE" >> crowdin.yml
43+
echo " translation: /$SOURCE_PATH/%locale%.json" >> crowdin.yml
44+
echo "" >> crowdin.yml
45+
done
46+
47+
- name: Copy translation files
48+
run: |
49+
TARGETS='${{ steps.read-targets.outputs.targets }}'
50+
echo "$TARGETS" | jq -c '.targets[]' | while read -r target; do
51+
SOURCE_PATH=$(echo "$target" | jq -r '.source_apth')
52+
F18N_PATH=$(echo "$target" | jq -r '.f18n_path')
53+
SOURCE_FILE=$(echo "$TARGETS" | jq -r '.source_file')
54+
echo "Copying $SOURCE_FILE from $SOURCE_PATH to $F18N_PATH"
55+
mkdir -p "$F18N_PATH"
56+
cp "floorp/$SOURCE_PATH/$SOURCE_FILE" "$F18N_PATH"
57+
done
58+
59+
- name: Commit and push changes
60+
run: |
61+
git config --local user.email "action@github.com"
62+
git config --local user.name "GitHub Action"
63+
git add .
64+
git commit -m "chore: sync translation target files and update crowdin.yml" || exit 0
65+
git push

0 commit comments

Comments
 (0)