Skip to content

Commit d886db7

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

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+
19+
- name: Read translation targets
20+
id: read-targets
21+
run: |
22+
TARGETS=$(cat floorp/src/apps/i18n-supports/translation-targets.json)
23+
echo "targets=$TARGETS" >> $GITHUB_OUTPUT
24+
25+
- name: Generate Crowdin.yml
26+
run: |
27+
TARGETS='${{ steps.read-targets.outputs.targets }}'
28+
echo "files:" > crowdin.yml
29+
echo "$TARGETS" | jq -c '.targets[]' | while read -r target; do
30+
SOURCE_PATH=$(echo "$target" | jq -r '.source_apth')
31+
SOURCE_FILE=$(echo "$TARGETS" | jq -r '.source_file')
32+
echo "" >> crowdin.yml
33+
echo " - source: /$SOURCE_PATH/$SOURCE_FILE" >> crowdin.yml
34+
echo " translation: /$SOURCE_PATH/%locale%.json" >> crowdin.yml
35+
done
36+
37+
- name: Copy translation files
38+
run: |
39+
TARGETS='${{ steps.read-targets.outputs.targets }}'
40+
echo "$TARGETS" | jq -c '.targets[]' | while read -r target; do
41+
SOURCE_PATH=$(echo "$target" | jq -r '.source_apth')
42+
F18N_PATH=$(echo "$target" | jq -r '.f18n_path')
43+
SOURCE_FILE=$(echo "$TARGETS" | jq -r '.source_file')
44+
echo "Copying $SOURCE_FILE from $SOURCE_PATH to $F18N_PATH"
45+
mkdir -p "$F18N_PATH"
46+
cp "floorp/$SOURCE_PATH/$SOURCE_FILE" "$F18N_PATH"
47+
done
48+
49+
- name: Commit and push changes
50+
run: |
51+
git config --local user.email "action@github.com"
52+
git config --local user.name "GitHub Action"
53+
git add .
54+
git commit -m "chore: sync translation target files and update crowdin.yml" || exit 0
55+
git push

0 commit comments

Comments
 (0)