Skip to content

Commit 1c208af

Browse files
committed
feat: translate
1 parent a6647b3 commit 1c208af

File tree

7 files changed

+567
-0
lines changed

7 files changed

+567
-0
lines changed

.github/workflows/translate.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: Auto Translate Docs
2+
3+
on:
4+
push:
5+
branches-ignore:
6+
- 'main'
7+
8+
jobs:
9+
translate:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout repository
13+
uses: actions/checkout@v4
14+
with:
15+
fetch-depth: 0 # Fetches all history for git diff
16+
token: ${{ secrets.GITHUB_TOKEN }}
17+
18+
- name: Set up Python
19+
uses: actions/setup-python@v4
20+
with:
21+
python-version: '3.9'
22+
23+
- name: Install dependencies
24+
run: pip install httpx aiofiles python-dotenv
25+
26+
- name: Get changed markdown files
27+
id: changed-files
28+
run: |
29+
# Get the list of changed files between the current and previous commit
30+
# We filter for .md and .mdx files that are inside the language directories
31+
files=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep -E '^(en|zh-hans|ja-jp|plugin-dev-en|plugin-dev-zh|plugin-dev-ja)/.*(\.md|\.mdx)$' || true)
32+
if [[ -z "$files" ]]; then
33+
echo "No markdown files to translate."
34+
echo "files=" >> $GITHUB_OUTPUT
35+
else
36+
# The script expects absolute paths, but we run it from the root, so relative is fine.
37+
echo "files<<EOF" >> $GITHUB_OUTPUT
38+
echo "$files" >> $GITHUB_OUTPUT
39+
echo "EOF" >> $GITHUB_OUTPUT
40+
fi
41+
42+
- name: Run translation script
43+
if: steps.changed-files.outputs.files
44+
env:
45+
DIFY_API_KEY: ${{ secrets.DIFY_API_KEY }}
46+
run: |
47+
echo "Files to translate:"
48+
echo "${{ steps.changed-files.outputs.files }}"
49+
50+
for file in ${{ steps.changed-files.outputs.files }}; do
51+
echo "Translating $file..."
52+
python tools/translate/main.py "$file" "$DIFY_API_KEY"
53+
done
54+
55+
- name: Commit and push changes
56+
run: |
57+
git config --global user.name 'github-actions[bot]'
58+
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
59+
# Check if there are any changes to commit
60+
if [[ -n $(git status --porcelain) ]]; then
61+
git add .
62+
git commit -m "docs: auto-translate documentation"
63+
# Push to the same branch the workflow was triggered from
64+
git push origin HEAD:${{ github.ref_name }}
65+
echo "Translated files have been pushed to the branch."
66+
else
67+
echo "No new translations to commit."
68+
fi

tools/translate/.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dify_api_key=your_dify_api_key_here

tools/translate/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.env

tools/translate/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

0 commit comments

Comments
 (0)