-
-
Notifications
You must be signed in to change notification settings - Fork 707
160 lines (144 loc) · 5.24 KB
/
auto-translate.yml
File metadata and controls
160 lines (144 loc) · 5.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
name: Auto-Translate Strings
on:
push:
branches:
- develop
paths:
- '**/en.lproj/Localizable.strings'
- '**/en.lproj/Strings.strings'
workflow_dispatch:
inputs:
base_ref:
description: 'Base git ref (before changes)'
required: false
default: 'HEAD~1'
head_ref:
description: 'Head git ref (with changes)'
required: false
default: 'HEAD'
strings_file:
description: 'Repo-relative path to en.lproj/Localizable.strings'
required: false
default: 'PVUI/Sources/PVSwiftUI/Resources/en.lproj/Localizable.strings'
languages:
description: 'Comma-separated language codes (empty = all)'
required: false
default: ''
dry_run:
description: 'Dry run — detect keys but skip API calls'
type: boolean
required: false
default: false
permissions:
contents: write
pull-requests: write
jobs:
translate:
name: Detect & translate new strings
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[Auto-translation]')"
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 2
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install dependencies
run: pip install anthropic
- name: Determine changed strings files
id: changed_files
run: |
FILES=$(git diff --name-only HEAD~1 HEAD -- '**/en.lproj/*.strings' 2>/dev/null || echo "")
echo "changed_files=$FILES" >> "$GITHUB_OUTPUT"
echo "Changed strings files: $FILES"
- name: Translate new/changed keys
id: translate
if: steps.changed_files.outputs.changed_files != ''
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
run: |
set -e
BASE_REF="${{ inputs.base_ref || 'HEAD~1' }}"
HEAD_REF="${{ inputs.head_ref || 'HEAD' }}"
DRY_RUN="${{ inputs.dry_run || 'false' }}"
LANG_FLAG=""
if [ -n "${{ inputs.languages }}" ]; then
LANGS=$(echo "${{ inputs.languages }}" | tr ',' ' ')
LANG_FLAG="--languages $LANGS"
fi
DRY_FLAG=""
if [ "$DRY_RUN" = "true" ]; then
DRY_FLAG="--dry-run"
fi
CHANGED="${{ steps.changed_files.outputs.changed_files }}"
for FILE in $CHANGED; do
echo "--- Processing: $FILE ---"
OUTPUT_DIR=$(dirname $(dirname "$FILE"))
python3 Scripts/auto_translate.py \
--base-ref "$BASE_REF" \
--head-ref "$HEAD_REF" \
--strings-file "$FILE" \
--output-dir "$OUTPUT_DIR" \
$LANG_FLAG $DRY_FLAG
done
- name: Check for translation changes
id: check_changes
run: |
if git diff --quiet; then
echo "has_changes=false" >> "$GITHUB_OUTPUT"
else
echo "has_changes=true" >> "$GITHUB_OUTPUT"
git diff --name-only
fi
- name: Create translation PR
if: steps.check_changes.outputs.has_changes == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
BRANCH="auto-translation/$(date +%Y%m%d-%H%M%S)"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git checkout -b "$BRANCH"
git add -A
git commit -m "[Auto-translation] Translate new/changed strings
Triggered by: ${{ github.sha }}
Source branch: ${{ github.ref_name }}
Auto-generated by Scripts/auto_translate.py using claude-haiku-4-5-20251001.
Please review all translations before merging."
git push origin "$BRANCH"
cat > /tmp/pr_body.md << 'PREOF'
## Auto-Translation: New/Changed Strings
### Review Checklist
- [ ] 🇨🇳 Simplified Chinese (`zh-Hans`)
- [ ] 🇯🇵 Japanese (`ja`)
- [ ] 🇰🇷 Korean (`ko`)
- [ ] 🇪🇸 Spanish (`es`)
- [ ] 🇧🇷 Brazilian Portuguese (`pt-BR`)
- [ ] 🇩🇪 German (`de`)
- [ ] 🇫🇷 French (`fr`)
- [ ] 🇮🇹 Italian (`it`)
- [ ] 🇳🇱 Dutch (`nl`)
- [ ] 🇷🇺 Russian (`ru`)
- [ ] 🇸🇦 Arabic (`ar`)
Part of #2871
PREOF
gh pr create \
--title "[Auto-translation] New/changed strings — $(date +%Y-%m-%d)" \
--body-file /tmp/pr_body.md \
--base develop \
--head "$BRANCH" \
--draft \
--label "translations" \
--assignee JoeMatt \
--repo "${{ github.repository }}" \
2>/dev/null || true
- name: No changes needed
if: steps.check_changes.outputs.has_changes == 'false'
run: echo "No translation changes produced — nothing to PR."
- name: Skip — no strings files changed
if: steps.changed_files.outputs.changed_files == ''
run: echo "No en.lproj/*.strings files changed in this push."