forked from Byeongcheol-Kim/Meditate
-
Notifications
You must be signed in to change notification settings - Fork 0
221 lines (201 loc) · 8.32 KB
/
Copy pathtranslate-content.yml
File metadata and controls
221 lines (201 loc) · 8.32 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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
name: Translate texts, guides, etc
run-name: Translate texts, guides, etc by @${{ github.actor }}
concurrency:
group: translate-content
cancel-in-progress: true
on:
push:
branches:
- "main"
paths:
- "UserGuide.md"
- "Advertisement.md"
- "ConnectIQStore/MeditateStoreDescription-en.txt"
- "userGuideScreenshots/hero_meditate.png"
- ".github/codex/prompts/translate-content.md"
- ".github/workflows/translate-content.yml"
jobs:
detect-changes:
name: Detect changes
runs-on: ubuntu-latest
outputs:
text_changed: ${{ steps.filter.outputs.text }}
image_changed: ${{ steps.filter.outputs.image }}
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
text:
- "UserGuide.md"
- "Advertisement.md"
- "ConnectIQStore/MeditateStoreDescription-en.txt"
- ".github/codex/prompts/translate-content.md"
- ".github/workflows/translate-content.yml"
image:
- "userGuideScreenshots/hero_meditate.png"
- ".github/workflows/translate-content.yml"
prepare-branch:
name: Prepare translation branch
needs: detect-changes
if: needs.detect-changes.outputs.text_changed == 'true' || needs.detect-changes.outputs.image_changed == 'true'
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- name: cleanup and create release-translation branch
run: |
git push -d origin release-translation || echo "no remote branch to cleanup"
git checkout -B release-translation
git push -f origin release-translation
translate-text:
name: Translate text
needs: [detect-changes, prepare-branch]
if: needs.detect-changes.outputs.text_changed == 'true'
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
ref: release-translation
- name: Translate via Codex
id: codex_translate
uses: openai/codex-action@v1
with:
openai-api-key: ${{ secrets.CHATGPT_TOKEN }}
prompt-file: .github/codex/prompts/translate-content.md
codex-args: --full-auto
safety-strategy: drop-sudo
sandbox: workspace-write
model: gpt-5.4
- name: Commit text translations
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add ./generated/
git commit -m "Update text translations" || echo "No text translation changes to commit"
git pull --rebase origin release-translation || true
git push origin release-translation
translate-images:
name: Translate hero image
needs: [detect-changes, prepare-branch]
if: needs.detect-changes.outputs.image_changed == 'true'
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
ref: release-translation
- name: Translate hero image for each language
shell: bash
env:
OPENAI_API_KEY: ${{ secrets.CHATGPT_TOKEN }}
run: |
pip install Pillow --quiet
declare -A LANG_FULL=([de]="German" [pt]="Brazilian Portuguese" [ko]="Korean" [es]="Spanish" [zh]="Chinese Simplified" [uk]="Ukrainian" [ja]="Japanese" [fr]="French")
SRC="userGuideScreenshots/hero_meditate.png"
mkdir -p generated/HeroImages
# Pad to 1536x1024 (nearest supported size) preserving center
python3 -c "
from PIL import Image
img = Image.open('$SRC').convert('RGB')
padded = Image.new('RGB', (1536, 1024), (0, 0, 0))
x = (1536 - img.width) // 2
y = (1024 - img.height) // 2
padded.paste(img, (x, y))
padded.save('/tmp/hero_padded.png')
"
for lang in "${!LANG_FULL[@]}"; do
lang_name="${LANG_FULL[$lang]}"
echo "Translating hero image to ${lang_name} (${lang})..."
prompt="You are editing a hero banner image for a Garmin watch meditation and breathwork app.
Translate ALL visible text in this image into ${lang_name}.
Rules:
- Translate the app name naturally (e.g. for German: \"Meditation & Atemübungen\"). Use the most idiomatic phrasing. Keep the & separator.
- Translate all other visible text naturally and fluently, as a native ${lang_name} speaker would write it. The tone is warm, gentle, and encouraging.
- Preserve the EXACT same visual design: background, colors, gradients, watch imagery, layout, typography style, text positioning, and text sizing.
- Only change the language of the text. Everything else must remain pixel-identical.
- The result must look professional and polished, as if it were the original design in ${lang_name}.
- Do NOT add any new text, watermarks, logos, or visual elements."
response=$(curl -s -X POST "https://api.openai.com/v1/images/edits" \
-H "Authorization: Bearer ${OPENAI_API_KEY}" \
-F "model=gpt-image-1" \
-F "image[]=@/tmp/hero_padded.png" \
-F "prompt=${prompt}" \
-F "size=1536x1024" \
-F "quality=high")
# Check for errors
error=$(echo "$response" | jq -r '.error.message // empty')
if [ -n "$error" ]; then
echo "::warning::Failed to translate hero image to ${lang_name}: ${error}"
continue
fi
# Decode base64 image
echo "$response" | jq -r '.data[0].b64_json' | base64 -d > "/tmp/hero_${lang}_raw.png"
# Crop back to center 2:1 ratio then resize to exact 1440x720
python3 -c "
from PIL import Image
img = Image.open('/tmp/hero_${lang}_raw.png').convert('RGB')
# Center crop to 1536x768
left = (img.width - 1536) // 2
top = (img.height - 768) // 2
img = img.crop((left, top, left + 1536, top + 768))
img = img.resize((1440, 720), Image.LANCZOS)
img.save('generated/HeroImages/hero_meditate-${lang}.png')
"
rm -f "/tmp/hero_${lang}_raw.png"
echo "Done: generated/HeroImages/hero_meditate-${lang}.png"
done
rm -f /tmp/hero_padded.png
- name: Commit image translations
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add ./generated/HeroImages/
git commit -m "Update hero image translations" || echo "No image translation changes to commit"
git pull --rebase origin release-translation || true
git push origin release-translation
create-pr:
name: Create or update PR
needs: [detect-changes, translate-text, translate-images]
if: always() && (needs.translate-text.result == 'success' || needs.translate-images.result == 'success')
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- name: Create or update PR to main
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const owner = context.repo.owner;
const repo = context.repo.repo;
const head = `${owner}:release-translation`;
const base = 'main';
const { data: pulls } = await github.rest.pulls.list({
owner,
repo,
head,
base,
state: 'open',
per_page: 10,
});
if (pulls.length > 0) {
core.info(`PR already exists: #${pulls[0].number}`);
return;
}
const { data: pr } = await github.rest.pulls.create({
owner,
repo,
head: 'release-translation',
base,
title: 'Update translations',
body: 'Automated translation updates generated by the translation workflow.',
maintainer_can_modify: true,
});
core.info(`Created PR: #${pr.number}`);