This GitHub Action detects changes in specified file types (Markdown, JSON, TXT, etc.), translates the modified content using OpenAI GPT-4, and commits the translations back to your repository.
- ✅ Supports multiple file extensions
- ✅ Preserves YAML front matter in markdown files
- ✅ Allows custom output file formats
- ✅ Automatically commits and pushes translated files
- Detects changed files (based on extensions like .md, .json, .txt).
- Extracts and preserves YAML front matter (if applicable).
- Sends content to OpenAI API for translation.
- Saves the translated version with a custom filename format (e.g., -fr.md, translated_.json).
- Commits and pushes the translated files back to the repository.
Add the following workflow to your .github/workflows/translate.yml
file (or add the step in any of your pipelines!):
name: Translate Files
on:
push:
branches:
- main
jobs:
translate:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Run Translation Action
uses: imaun/gpt-translate-action@v1.0
with:
openai_api_key: ${{ secrets.OPENAI_API_KEY }}
target_lang: "French"
target_lang_code: "fr"
file_extensions: "md,json,txt"
output_format: "translated_*.{ext}"
openai_api_key
(Required): Your OpenAI API key (stored as a GitHub Secret).target_lang
: The language to translate into (default: Persian).target_lang_code
: The language code to be used in output format (default: fa).file_exts
: Comma-separated list of file types to process (default: md).output_format
: Format for translated files. Use {lang} for language and {ext} for extension.
*-{lang}.{ext}
: about-fa.mdtranslated_*.{ext}
: translated_about.json
- Go to Settings → Secrets and Variables → Actions in your repository.
- Click New Repository Secret.
- Add a secret named
OPENAI_API_KEY
and paste your OpenAI API key.
Original Markdown (about.md):
---
slug: "about"
title: "About Me"
author: "John Doe"
description: "This is my personal website."
---
Welcome to my personal website! Here you can find my projects and blog posts.
Translated (about-fr.md for French):
---
slug: "about"
title: "À propos de moi"
author: "John Doe"
description: "Ceci est mon site Web personnel."
---
Bienvenue sur mon site personnel ! Vous pouvez y trouver mes projets et articles de blog.
docker build -t translate-action .
docker run -e OPENAI_API_KEY="your-api-key" -e TARGET_LANG="French" TARGET_LANG_CODE="fr" translate-action