|
1
|
name: Admin i18n Sync |
|
2
|
|
|
3
|
on: |
|
4
|
schedule: |
|
5
|
- cron: "0 6 * * *" # Every day at 06:00 UTC |
|
6
|
workflow_dispatch: |
|
7
|
|
|
8
|
concurrency: |
|
9
|
group: admin-i18n-sync |
|
10
|
cancel-in-progress: false |
|
11
|
|
|
12
|
env: |
|
13
|
BRANCH: chore/admin-i18n-sync-translations |
|
14
|
SYNC_SCRIPT: packages/admin/dashboard/scripts/i18n/sync-translations.js |
|
15
|
|
|
16
|
jobs: |
|
17
|
detect: |
|
18
|
runs-on: ubuntu-latest |
|
19
|
permissions: |
|
20
|
contents: read |
|
21
|
pull-requests: read |
|
22
|
outputs: |
|
23
|
locales: ${{ steps.missing.outputs.locales }} |
|
24
|
steps: |
|
25
|
- name: Check for an open sync PR |
|
26
|
id: open-pr |
|
27
|
env: |
|
28
|
GH_TOKEN: ${{ github.token }} |
|
29
|
REPO: ${{ github.repository }} |
|
30
|
run: | |
|
31
|
PR_NUMBER=$(gh api "repos/$REPO/pulls?head=${REPO%%/*}:$BRANCH&state=open" --jq '.[0].number // ""') |
|
32
|
if [ -n "$PR_NUMBER" ]; then |
|
33
|
echo "PR #$PR_NUMBER is still open, skipping until it's merged or closed." |
|
34
|
fi |
|
35
|
echo "number=$PR_NUMBER" >> "$GITHUB_OUTPUT" |
|
36
|
|
|
37
|
- name: Checkout repository |
|
38
|
if: steps.open-pr.outputs.number == '' |
|
39
|
uses: actions/checkout@v4 |
|
40
|
with: |
|
41
|
ref: develop |
|
42
|
|
|
43
|
- name: Set up Node.js |
|
44
|
if: steps.open-pr.outputs.number == '' |
|
45
|
uses: actions/setup-node@v4 |
|
46
|
with: |
|
47
|
node-version: "22" |
|
48
|
|
|
49
|
- name: Find missing translations |
|
50
|
id: missing |
|
51
|
if: steps.open-pr.outputs.number == '' |
|
52
|
run: | |
|
53
|
node "$SYNC_SCRIPT" missing --output /tmp/missing.json |
|
54
|
echo "locales=$(jq -c 'keys' /tmp/missing.json)" >> "$GITHUB_OUTPUT" |
|
55
|
|
|
56
|
- name: Upload missing translations report |
|
57
|
if: steps.open-pr.outputs.number == '' |
|
58
|
uses: actions/upload-artifact@v4 |
|
59
|
with: |
|
60
|
name: i18n-missing |
|
61
|
path: /tmp/missing.json |
|
62
|
|
|
63
|
translate: |
|
64
|
needs: detect |
|
65
|
if: needs.detect.outputs.locales != '' && needs.detect.outputs.locales != '[]' |
|
66
|
runs-on: ubuntu-latest |
|
67
|
permissions: |
|
68
|
contents: read |
|
69
|
strategy: |
|
70
|
fail-fast: false |
|
71
|
max-parallel: 8 |
|
72
|
matrix: |
|
73
|
locale: ${{ fromJSON(needs.detect.outputs.locales) }} |
|
74
|
steps: |
|
75
|
- name: Checkout repository |
|
76
|
uses: actions/checkout@v4 |
|
77
|
with: |
|
78
|
ref: develop |
|
79
|
|
|
80
|
- name: Download missing translations report |
|
81
|
uses: actions/download-artifact@v4 |
|
82
|
with: |
|
83
|
name: i18n-missing |
|
84
|
path: /tmp/report |
|
85
|
|
|
86
|
- name: Extract missing keys for ${{ matrix.locale }} |
|
87
|
env: |
|
88
|
LOCALE: ${{ matrix.locale }} |
|
89
|
run: | |
|
90
|
mkdir -p /tmp/i18n/translations |
|
91
|
jq --arg locale "$LOCALE" '.[$locale]' /tmp/report/missing.json > /tmp/i18n/missing.json |
|
92
|
echo "Missing keys: $(jq '.count' /tmp/i18n/missing.json)" |
|
93
|
|
|
94
|
- name: Translate with Claude |
|
95
|
uses: anthropics/claude-code-base-action@132be24009ca6f292db66a3d1d5a17249cf68a5d # main, installs Claude Code 2.1.282 |
|
96
|
with: |
|
97
|
anthropic_api_key: ${{ secrets.CLAUDE_CODE_API_TOKEN }} |
|
98
|
claude_args: >- |
|
99
|
--model claude-sonnet-4-6 |
|
100
|
--max-turns 60 |
|
101
|
--allowedTools "Read,Write,Grep" |
|
102
|
prompt: | |
|
103
|
You are translating missing UI strings for the Medusa admin dashboard into the "${{ matrix.locale }}" locale. |
|
104
|
|
|
105
|
## Input |
|
106
|
|
|
107
|
Read /tmp/i18n/missing.json. It has: |
|
108
|
- `count`: the number of missing strings. |
|
109
|
- `pluralForms`: the i18next plural forms this locale uses. |
|
110
|
- `missing`: a nested object mirroring en.json that contains only the missing keys, with the English source text as each value. Plural keys (ending in `_zero`, `_one`, `_two`, `_few`, `_many`, `_other`) are already expanded to this locale's plural forms; forms that English doesn't have use the English `_other` text as the source. |
|
111
|
|
|
112
|
The existing translations for this locale are in packages/admin/dashboard/src/i18n/translations/${{ matrix.locale }}.json. Use the Grep tool on that file to look up how related terms are already translated (e.g. "order", "product", "sales channel", "refund") and stay consistent with that terminology and tone. Do not read the whole file. |
|
113
|
|
|
114
|
## Rules |
|
115
|
|
|
116
|
- Translate every value in `missing`. Keep every key and the nesting exactly as given; never rename, add, or drop keys. |
|
117
|
- Keep i18next placeholders like `{{count}}` or `{{name}}` exactly as written, untranslated. The only exception: plural forms may add or drop `{{count}}` when the grammar of the locale needs it. |
|
118
|
- Keep Trans component tags like `<0>`, `</0>`, and `<0/>` exactly, wrapping the equivalent words in the translation. |
|
119
|
- Keep product names, code identifiers, and units (e.g. "Medusa", "API", "JSON", "lb") as-is unless the locale's existing translations already localize them. |
|
120
|
- Match the register and style of the existing translations (formal vs. informal address, capitalization of titles and buttons). |
|
121
|
- Write each plural form grammatically correct for its category in this locale. |
|
122
|
|
|
123
|
## Output |
|
124
|
|
|
125
|
Write the translations with the Write tool as JSON files in /tmp/i18n/translations/, using the same nested shape as `missing`. |
|
126
|
- Split the output into parts of at most 150 strings each, named ${{ matrix.locale }}.part-1.json, ${{ matrix.locale }}.part-2.json, and so on. Each part holds a disjoint subset of the keys, nested the same way as `missing`. |
|
127
|
- Each file must be valid JSON containing only string values and nested objects. |
|
128
|
- Do not modify any file in the repository. |
|
129
|
|
|
130
|
- name: Upload translations |
|
131
|
uses: actions/upload-artifact@v4 |
|
132
|
with: |
|
133
|
name: i18n-translations-${{ matrix.locale }} |
|
134
|
path: /tmp/i18n/translations/ |
|
135
|
if-no-files-found: warn |
|
136
|
|
|
137
|
open-pr: |
|
138
|
needs: translate |
|
139
|
if: always() && needs.translate.result != 'skipped' && needs.translate.result != 'cancelled' |
|
140
|
runs-on: ubuntu-latest |
|
141
|
permissions: |
|
142
|
contents: write |
|
143
|
pull-requests: write |
|
144
|
steps: |
|
145
|
- name: Generate GitHub App token |
|
146
|
id: app-token |
|
147
|
uses: actions/create-github-app-token@v1 |
|
148
|
with: |
|
149
|
app-id: ${{ secrets.MEDUSA_APP_ID }} |
|
150
|
private-key: ${{ secrets.MEDUSA_APP_PRIVATE_KEY }} |
|
151
|
|
|
152
|
- name: Checkout repository |
|
153
|
uses: actions/checkout@v4 |
|
154
|
with: |
|
155
|
ref: develop |
|
156
|
token: ${{ steps.app-token.outputs.token }} |
|
157
|
|
|
158
|
- name: Set up Node.js |
|
159
|
uses: actions/setup-node@v4 |
|
160
|
with: |
|
161
|
node-version: "22" |
|
162
|
|
|
163
|
- name: Download translations |
|
164
|
uses: actions/download-artifact@v4 |
|
165
|
with: |
|
166
|
pattern: i18n-translations-* |
|
167
|
path: /tmp/i18n/translations |
|
168
|
merge-multiple: true |
|
169
|
|
|
170
|
- name: Apply translations |
|
171
|
id: apply |
|
172
|
shell: bash |
|
173
|
run: | |
|
174
|
node "$SYNC_SCRIPT" missing > /tmp/before.txt |
|
175
|
node "$SYNC_SCRIPT" apply --input /tmp/i18n/translations 2>&1 | tee /tmp/apply.log |
|
176
|
node "$SYNC_SCRIPT" missing > /tmp/after.txt |
|
177
|
|
|
178
|
if git diff --quiet -- packages/admin/dashboard/src/i18n/translations; then |
|
179
|
echo "has_changes=false" >> "$GITHUB_OUTPUT" |
|
180
|
echo "No translation changes to commit." |
|
181
|
else |
|
182
|
echo "has_changes=true" >> "$GITHUB_OUTPUT" |
|
183
|
fi |
|
184
|
|
|
185
|
- name: Commit and push |
|
186
|
if: steps.apply.outputs.has_changes == 'true' |
|
187
|
run: | |
|
188
|
git config user.name "github-actions[bot]" |
|
189
|
git config user.email "github-actions[bot]@users.noreply.github.com" |
|
190
|
git checkout -B "$BRANCH" |
|
191
|
git add packages/admin/dashboard/src/i18n/translations |
|
192
|
git commit -m "chore(dashboard): add missing translations" |
|
193
|
git push --force origin "$BRANCH" |
|
194
|
|
|
195
|
- name: Create Pull Request |
|
196
|
if: steps.apply.outputs.has_changes == 'true' |
|
197
|
env: |
|
198
|
GH_TOKEN: ${{ steps.app-token.outputs.token }} |
|
199
|
REPO: ${{ github.repository }} |
|
200
|
run: | |
|
201
|
BODY_FILE=$(mktemp) |
|
202
|
{ |
|
203
|
echo "## Add missing admin dashboard translations" |
|
204
|
echo "" |
|
205
|
echo "Translates strings in \`en.json\` that are missing from the other locale files. Translations were generated by Claude." |
|
206
|
echo "" |
|
207
|
echo "### Missing translations" |
|
208
|
echo "" |
|
209
|
echo "| Before | After |" |
|
210
|
echo "| --- | --- |" |
|
211
|
echo "| $(tail -n 1 /tmp/before.txt) | $(tail -n 1 /tmp/after.txt) |" |
|
212
|
if grep -q "^Skipped keys\|^Skipping" /tmp/apply.log; then |
|
213
|
echo "" |
|
214
|
echo "<details><summary>Rejected translations (retried on the next run)</summary>" |
|
215
|
echo "" |
|
216
|
echo '```' |
|
217
|
grep -A1000 "^Skipped keys\|^Skipping" /tmp/apply.log | grep -v "^Updated " | head -n 200 |
|
218
|
echo '```' |
|
219
|
echo "</details>" |
|
220
|
fi |
|
221
|
echo "" |
|
222
|
echo "> Review carefully before merging, ideally with a native speaker for each locale." |
|
223
|
} > "$BODY_FILE" |
|
224
|
|
|
225
|
PR_NUMBER=$(gh api "repos/$REPO/pulls" \ |
|
226
|
--method POST \ |
|
227
|
--field title="chore(dashboard): add missing translations [automated]" \ |
|
228
|
--field body="$(cat "$BODY_FILE")" \ |
|
229
|
--field base="develop" \ |
|
230
|
--field head="$BRANCH" \ |
|
231
|
--jq '.number') |
|
232
|
echo "Created PR #$PR_NUMBER" |