Skip to content

FidelusAleksander/ai-translate-action

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

AI Translate Action 🌐

Run Tests License: MIT GitHub release (latest by date)

English Polish Spanish Chinese

A GitHub Action that provides AI-powered text translation directly in your workflows.

Basic Usage 🚀

Translate text directly

- uses: FidelusAleksander/ai-translate-action@v1
  with:
    text: "Hello, world!"
    target-language: "Spanish"

Translate a text file

- uses: FidelusAleksander/ai-translate-action@v1
  with:
    text-file: README.md
    target-language: "French"

Permissions 🔒

This action requires at minimum the following permissions set.

permissions:
  models: read

Inputs ⚙️

Input Description Required Default
text The text to translate No* -
text-file Path to a file containing the text to translate No* -
target-language The language to translate the text into Yes -
token Personal access token No ${{ github.token }}
model The AI model to use. See available models No gpt-4o
custom-instructions Optional additional instructions to customize translation behavior (e.g., "Don't translate code blocks" or "Keep technical terms in English") No -

* Either text or text-file must be provided

Outputs 📤

Output Description
translated-text The translated text

Cool examples 🎮

Have you come up with a clever use of this action? Open a PR to showcase it here for the world to see!

Auto-translate README to multiple languages

This action can be used to automatically translate your README into multiple languages whenever changes are made. Here's how this repository keeps its documentation in sync:

name: Translate README

on:
  push:
    branches:
      - main
    paths:
      - "README.md"

permissions:
  contents: write
  pull-requests: write
  models: read

jobs:
  translate:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        language: ["spanish", "chinese"]
        include:
          - language: "spanish"
            file: "README.es.md"
          - language: "chinese"
            file: "README.zh.md"

    steps:
      - uses: actions/checkout@v4

      - name: Translate README
        uses: FidelusAleksander/ai-translate-action@v1
        id: translate
        with:
          text-file: "README.md"
          target-language: ${{ matrix.language }}
          custom-instructions: "Keep technical terms in English. Don't translate code blocks"

      - name: Save translation
        run: |
          mkdir -p docs
          echo "$TRANSLATED_TEXT" | tee docs/${{ matrix.file }}
        env:
          TRANSLATED_TEXT: ${{ steps.translate.outputs.translated-text }}

      - name: Upload translation artifact
        uses: actions/upload-artifact@v4
        with:
          name: ${{ matrix.file }}
          path: docs/${{ matrix.file }}

  create-pr:
    needs: translate
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/download-artifact@v4
        with:
          path: docs
          merge-multiple: true
      - name: Create Pull Request
        uses: peter-evans/create-pull-request@v6
        with:
          commit-message: "docs: update translations of README"
          title: "docs: update translations of README"
          body: |
            This PR updates all translations of the README:

            Changes were automatically generated using the [ai-translate-action](https://github.com/FidelusAleksander/ai-translate-action) action.
          branch: docs/update-readme-translations
          add-paths: "docs/README*"
          delete-branch: true
          labels: |
            documentation

This workflow automatically translates the README into Spanish and Chinese whenever changes are made to the English version. It creates a pull request with the updated translations, making it easy to review the changes before merging.

About

GitHub Action for AI-powered file translation between different languages

Topics

Resources

License

Stars

Watchers

Forks

Contributors 4

  •  
  •  
  •  
  •