From feba2032d12156292d4566923d9e7ab7ae6532b6 Mon Sep 17 00:00:00 2001 From: CodingMan Date: Wed, 9 Jul 2025 10:55:53 +0800 Subject: [PATCH 1/3] feat: add readme file translate. --- .github/workflows/translate_readme.yml | 54 ++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 .github/workflows/translate_readme.yml diff --git a/.github/workflows/translate_readme.yml b/.github/workflows/translate_readme.yml new file mode 100644 index 0000000..5293e80 --- /dev/null +++ b/.github/workflows/translate_readme.yml @@ -0,0 +1,54 @@ +name: Translate README with Gemini + +on: + push: + branches-ignore: + - 'main' + paths: + - 'README.md' + +jobs: + translate: + runs-on: ubuntu-latest + permissions: + contents: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Read README.md content + id: read_readme + run: | + content=$(cat README.md) + # Escape for JSON and multiline env var + content="${content//'%'/'%25'}" + content="${content//$' +'/'\n'}" + content="${content//$''/'\r'}" + echo "readme_content<> $GITHUB_ENV + echo "$content" >> $GITHUB_ENV + echo "EOF" >> $GITHUB_ENV + + - name: Call Gemini API for Translation + id: call_gemini + uses: google-gemini/gemini-api-action@v1 + with: + api_key: ${{ secrets.GEMINI_API_KEY }} + prompt: "Please translate the following Markdown text from Traditional Chinese to English. It is for a GitHub project's README file. Preserve all original Markdown formatting, including code blocks, links, tables, and HTML tags. Do not add any extra commentary, introductions, or explanations outside of the translated text itself. Just return the pure, translated Markdown content. Here is the text:\n\n${{ env.readme_content }}" + + - name: Update README_ENG.md with translation + run: | + echo "${{ steps.call_gemini.outputs.response }}" > README_ENG.md + + - name: Commit and push if changed + run: | + git config --global user.name 'github-actions[bot]' + git config --global user.email 'github-actions[bot]@users.noreply.github.com' + git add README_ENG.md + if ! git diff --staged --quiet; then + git commit -m "docs: auto-translate README.md to English via Gemini" + git push + else + echo "No changes to commit." + fi From d2915136d35303f4c969f333897bf149f140bb85 Mon Sep 17 00:00:00 2001 From: CodingMan Date: Wed, 9 Jul 2025 11:08:53 +0800 Subject: [PATCH 2/3] fix: Corrected YAML syntax in translate_readme.yml workflow --- .github/workflows/translate_readme.yml | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/.github/workflows/translate_readme.yml b/.github/workflows/translate_readme.yml index 5293e80..03edf40 100644 --- a/.github/workflows/translate_readme.yml +++ b/.github/workflows/translate_readme.yml @@ -18,24 +18,17 @@ jobs: uses: actions/checkout@v4 - name: Read README.md content - id: read_readme - run: | - content=$(cat README.md) - # Escape for JSON and multiline env var - content="${content//'%'/'%25'}" - content="${content//$' -'/'\n'}" - content="${content//$''/'\r'}" - echo "readme_content<> $GITHUB_ENV - echo "$content" >> $GITHUB_ENV - echo "EOF" >> $GITHUB_ENV + id: read_file + uses: jellyfishsdk/read-file-action@v1 + with: + path: 'README.md' - name: Call Gemini API for Translation id: call_gemini uses: google-gemini/gemini-api-action@v1 with: api_key: ${{ secrets.GEMINI_API_KEY }} - prompt: "Please translate the following Markdown text from Traditional Chinese to English. It is for a GitHub project's README file. Preserve all original Markdown formatting, including code blocks, links, tables, and HTML tags. Do not add any extra commentary, introductions, or explanations outside of the translated text itself. Just return the pure, translated Markdown content. Here is the text:\n\n${{ env.readme_content }}" + prompt: "Please translate the following Markdown text from Traditional Chinese to English. It is for a GitHub project's README file. Preserve all original Markdown formatting, including code blocks, links, tables, and HTML tags. Do not add any extra commentary, introductions, or explanations outside of the translated text itself. Just return the pure, translated Markdown content. Here is the text:\n\n${{ steps.read_file.outputs.content }}" - name: Update README_ENG.md with translation run: | @@ -51,4 +44,4 @@ jobs: git push else echo "No changes to commit." - fi + fi \ No newline at end of file From cf55c6fdc408ddcca066e82bcccedb212cd06072 Mon Sep 17 00:00:00 2001 From: CodingMan Date: Wed, 9 Jul 2025 11:08:53 +0800 Subject: [PATCH 3/3] fix: Corrected YAML syntax in translate_readme.yml workflow --- .github/workflows/code_quality.yml | 2 +- .github/workflows/translate_readme.yml | 20 +++++++------------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/.github/workflows/code_quality.yml b/.github/workflows/code_quality.yml index 8ef50d1..aac728f 100644 --- a/.github/workflows/code_quality.yml +++ b/.github/workflows/code_quality.yml @@ -9,7 +9,7 @@ jobs: lint_and_type_check: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up Python uses: actions/setup-python@v4 with: diff --git a/.github/workflows/translate_readme.yml b/.github/workflows/translate_readme.yml index 5293e80..e56bcc6 100644 --- a/.github/workflows/translate_readme.yml +++ b/.github/workflows/translate_readme.yml @@ -6,6 +6,7 @@ on: - 'main' paths: - 'README.md' + workflow_dispatch: jobs: translate: @@ -18,24 +19,17 @@ jobs: uses: actions/checkout@v4 - name: Read README.md content - id: read_readme - run: | - content=$(cat README.md) - # Escape for JSON and multiline env var - content="${content//'%'/'%25'}" - content="${content//$' -'/'\n'}" - content="${content//$''/'\r'}" - echo "readme_content<> $GITHUB_ENV - echo "$content" >> $GITHUB_ENV - echo "EOF" >> $GITHUB_ENV + id: read_file + uses: jellyfishsdk/read-file-action@v1 + with: + path: 'README.md' - name: Call Gemini API for Translation id: call_gemini uses: google-gemini/gemini-api-action@v1 with: api_key: ${{ secrets.GEMINI_API_KEY }} - prompt: "Please translate the following Markdown text from Traditional Chinese to English. It is for a GitHub project's README file. Preserve all original Markdown formatting, including code blocks, links, tables, and HTML tags. Do not add any extra commentary, introductions, or explanations outside of the translated text itself. Just return the pure, translated Markdown content. Here is the text:\n\n${{ env.readme_content }}" + prompt: "Please translate the following Markdown text from Traditional Chinese to English. It is for a GitHub project's README file. Preserve all original Markdown formatting, including code blocks, links, tables, and HTML tags. Do not add any extra commentary, introductions, or explanations outside of the translated text itself. Just return the pure, translated Markdown content. Here is the text:\n\n${{ steps.read_file.outputs.content }}" - name: Update README_ENG.md with translation run: | @@ -51,4 +45,4 @@ jobs: git push else echo "No changes to commit." - fi + fi \ No newline at end of file