GPT Translate GitHub Action
repository·master·Indexed 42 days ago
https://github.com/3ru/gpt-translateA GitHub Action for automating the translation of Markdown (.md), MDX (.mdx), and JSON (.json) files into multiple languages. It is triggered via issue or pull request comments using /gpt-translate or /gt commands and supports various AI providers including OpenAI, Anthropic, Google Gemini, Azure, Perplexity, Groq, Fireworks AI, Mistral AI, and Cohere. Version 1.2.2.
What's inside GPT Translate
- GPT-Translate is a GitHub workflow designed to help developers implement internationalization (i18n) for their documentation easily. It automates the translation process for documentation written in any language, allowing projects to deliver content to a global audience without the high manual cost of translating extensive documentation files.
Understand supported languages for translation
masterThe translation capabilities of
gpt-translateare determined by the underlying LLM used (GPT-3.5orGPT-4).- General Rule: Any language interpreted by
GPT-3.5orGPT-4can be translated. - Accuracy Factors: Translation accuracy is highly dependent on the amount of training data available for a specific language. Languages with fewer speakers (and thus less training data) may result in lower translation accuracy.
- Performance Trends: While not a direct evaluation of translation quality, OpenAI's MMLU (Massive Multitask Language Understanding) benchmarks indicate that model performance generally follows a trend based on language prevalence.
- General Rule: Any language interpreted by
Supported File Types and Languages
masterSupported File Formats
The action currently only supports translating the following file types:
- Markdown (
.md) - Markdown-JSX (
.mdx) - JSON (
.json)
Supported Languages
You can translate into any language that can be interpreted by GPT-4 or GPT-3.5.
- Markdown (
Understand the costs associated with translation
masterWhile the GitHub Actions workflow used bygpt-translateis free to run, the translation process relies on the OpenAI API, which is a paid service. Users are responsible for any costs incurred via their OpenAI account based on OpenAI API Pricing.Cost and pricing for gpt-translate
masterWhile the GitHub Actions workflow used bygpt-translateis free to run, you must pay for the usage of the OpenAI API used to perform the translations. You can check the current rates at the OpenAI API pricing page.Supported languages and providers
masterLanguages
The bot supports any language that can be interpreted by GPT-4 or GPT-3.5.
AI Providers
While the default configuration often uses OpenAI, the project supports multiple providers including:
- OpenAI
- Azure OpenAI
- Anthropic
- Perplexity
- Google Gemini
- Groq
- Fireworks AI
- Mistral AI
- Cohere
Best practices for Markdown (`.md`) translation
masterWhen translating large Markdown files, avoid extremely long sentences or blocks of text without line breaks.
If a text block contains approximately 80,000 consecutive characters without line breaks (specifically when using
gpt-3.5), it may cause errors during the splitting process. To ensure successful translation, use frequent line breaks to separate paragraphs or sections.You can measure the token count of your text using the official OpenAI tokenizer.
# Friendly format (Recommended) This is a sample novel. Once upon a time...Customize translation behavior with `prompt`
masterThe
promptargument allows you to define a custom instruction for the AI model to follow during translation. You can use dynamic variables within curly braces{}to inject context into your prompt:{targetLanguage}: The desired language for translation.{targetFileExt}: The desired file extension (e.g.,.md).
Example configuration using a custom prompt:
with: apikey: ${{ secrets.OPENAI_API_KEY }} prompt: 'Please translate the given text into naturalistic {targetLanguage} and output it in {targetFileExt} format.'with: apikey: ${{ secrets.OPENAI_API_KEY }} prompt: 'Please translate the given text into naturalistic {targetLanguage}.'Setup GPT Translate GitHub Action
masterTo use GPT Translate, you must configure your repository permissions and secrets to allow the action to write files and access AI models.
1. Repository Permissions
Navigate to Settings > Actions > General and enable:
Read and write permissionsAllow GitHub Actions to create and approve pull requests
2. Configure API Secrets
Navigate to Settings > Secrets and variables > Actions and add your AI provider's API key as a secret named
OPENAI_API_KEY(or the relevant key for your provider).3. Workflow Configuration
Create a workflow file (e.g.,
.github/workflows/gpt-translate.yml). It is highly recommended to trigger the action only when a specific comment is made to save runtime costs.Minimum Workflow Example:
# .github/workflows/gpt-translate.yml name: GPT Translate on: issue_comment: types: [ created ] jobs: gpt_translate: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Run GPT Translate if: | contains(github.event.comment.body, '/gpt-translate') || contains(github.event.comment.body, '/gt') uses: 3ru/gpt-translate@master with: apikey: ${{ secrets.OPENAI_API_KEY }}Configure the OPENAI_API_KEY secret
masterThe bot requires an OpenAI API key to perform translations. You must add this key as a repository secret so the GitHub Action can access it.
- Navigate to
Settings > Secrets and variables > Actionsin your repository. - Create a new secret with the name
OPENAI_API_KEY. - Paste your OpenAI API key as the value.
- Navigate to
Set up GPT Translate GitHub Action
masterTo use GPT Translate, you must configure your repository permissions and secrets, then create a workflow file.
1. Repository Settings
- Permissions: Navigate to
Settings > Actions > Generaland enableRead and write permissions. Also, enableAllow GitHub Actions to create and approve pull requests. - Secrets: Navigate to
Settings > Secrets and variables > Actionsand add your AI provider's API key as a secret namedOPENAI_API_KEY(or the relevant key for your provider).
2. Workflow Configuration
Create a workflow file (e.g.,
.github/workflows/gpt-translate.yml). The workflow must:- Use
actions/checkout@v4(or similar) to check out the repository. - Trigger on
issue_commentwithtypes: [ created ]. - Provide the API key via the
apikeyinput.
It is recommended to use a conditional
ifcheck so the action only runs when a specific command is mentioned in the comment to save execution time.# .github/workflows/gpt-translate.yml name: GPT Translate on: issue_comment: types: [ created ] jobs: gpt_translate: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Run GPT Translate if: | contains(github.event.comment.body, '/gpt-translate') || contains(github.event.comment.body, '/gt') uses: 3ru/gpt-translate@master with: apikey: ${{ secrets.OPENAI_API_KEY }}- Permissions: Navigate to
Configure the command-based translation workflow
masterTo enable command-based translation, create a GitHub Actions workflow file (e.g.,
.github/workflows/gpt-translate.yml) with the following configuration.Important Requirements:
- Checkout the repository: You must include
actions/checkout@v3before the translation step so the action has access to the files in your repository. - Conditional Execution: Use an
ifstatement to ensure the action only runs when/gpt-translateor/gtis detected in the comment body. - API Key: Pass your OpenAI API key via a GitHub Secret (e.g.,
OPENAI_API_KEY).
name: GPT翻译 on: issue_comment: types: [created] jobs: gpt_translate: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: 运行GPT翻译 if: | contains(github.event.comment.body, '/gpt-translate') || contains(github.event.comment.body, '/gt') uses: 3ru/gpt-translate@master with: apikey: ${{ secrets.OPENAI_API_KEY }}- Checkout the repository: You must include