GitHub Actions
AI translation with GitHub Actions and Lingo.dev CI/CD
What is GitHub Actions?
GitHub Actions is a CI/CD and automation platform built into GitHub. It lets users define workflows in YAML files to build, test, and deploy code or automate tasks triggered by repository events.
What is Lingo.dev CI/CD?
Lingo.dev CI/CD is an AI-powered tool for localizing apps and content in CI/CD, ensuring translations never fall out of date. For GitHub, Lingo.dev provides a custom GitHub Action that simplifies integration.
About this guide
This guide explains how to set up Lingo.dev CI/CD with the Lingo.dev GitHub Action and Lingo.dev Engine.
Step 1. Set up Lingo.dev CLI
To begin, follow the Quickstart for Lingo.dev CLI.
You should end up with:
- an API key for Lingo.dev
- an
i18n.jsonfile that configures the behavior of a translation pipeline - the ability to translate content with
npx lingo.dev@latest run
Step 2. Configure a repository secret
- Navigate to Settings > Secrets and variables > Actions.
- Click New repository secret.
- In the Name field, enter
LINGODOTDEV_API_KEY. - In the Secret field, enter a Lingo.dev API key.
- Click Add secret.
Step 3. Choose a workflow
You can set up Lingo.dev CI/CD in different ways to support different workflows. These are some of the workflows that we recommend (and provide examples for):
- When content is merged into
main, commit translations tomain - When content is merged into
main, create a pull request frommain - When content is merged into a feature branch, commit translations to the branch
- When content is merged into a feature branch, create a pull request from the branch
But there is no "best" workflow. They all have trade-offs. If you're not sure where to begin, we recommend starting with with the first option. It's the simplest, most invisible workflow.
Step 4. Set up the workflow
-
In the repo, create a
.github/workflowsdirectory:mkdir -p .github/workflowsBe sure to include the
.at the start of.github. -
In the
.github/workflowsdirectory, create a YAML file:touch .github/workflows/translate.ymlThe name of the file is not important.
-
Copy one of the example workflows into the file.
-
If the workflow creates pull requests:
- Navigate to Settings > Actions > General.
- Enable Allow GitHub Actions to create and approve pull requests.
- Click Save.
-
Commit and push the changes to the
mainbranch:git add .github/workflows/translate.yml git commit -m "feat: GitHub action for Lingo.dev" git push
(Optional) Step 5. Customize the workflow
Lingo.dev CI/CD has default values that, in most cases, don't need to be customized. You can override them by passing inputs to the GitHub Action:
Available inputs:
version: Lingo.dev CLI version (default:"latest")api-key: Lingo.dev Platform API Key (required)pull-request: Create a pull request with changes (default:false)commit-message: Custom commit message (default:"feat: update translations via @LingoDotDev")pull-request-title: Custom pull request title (default:"feat: update translations via @LingoDotDev")commit-author-name: Git commit author name (default:"Lingo.dev")commit-author-email: Git commit author email (default:"[email protected]")working-directory: Working directory (default:".")process-own-commits: Process commits made by this action (default:false)parallel: Run in parallel mode (default:false)
Example with custom inputs:
- name: Lingo.dev
uses: lingodotdev/lingo.dev@main
with:
api-key: ${{ secrets.LINGODOTDEV_API_KEY }}
commit-message: "My custom commit message!"
parallel: true
Example workflows
Commit to main
When content is merged into main, commit translations to main.
name: Translate
on:
push:
branches: [main]
permissions:
contents: write
jobs:
translate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Lingo.dev
uses: lingodotdev/lingo.dev@main
with:
api-key: ${{ secrets.LINGODOTDEV_API_KEY }}
Pull request from main
When content is merged into main, create a pull request from main.
name: Translate
on:
push:
branches: [main]
permissions:
contents: write
pull-requests: write
jobs:
translate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Lingo.dev
uses: lingodotdev/lingo.dev@main
with:
api-key: ${{ secrets.LINGODOTDEV_API_KEY }}
pull-request: true
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Commit to feature branch
When content is merged into a feature branch, commit translations to the branch.
name: Translate
on:
push:
branches-ignore: [main]
permissions:
contents: write
jobs:
translate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Lingo.dev
uses: lingodotdev/lingo.dev@main
with:
api-key: ${{ secrets.LINGODOTDEV_API_KEY }}
Pull request from feature branch
When content is merged into a feature branch, create a pull request from the branch.
name: Translate
on:
push:
branches-ignore: [main]
permissions:
contents: write
pull-requests: write
jobs:
translate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Lingo.dev
uses: lingodotdev/lingo.dev@main
with:
api-key: ${{ secrets.LINGODOTDEV_API_KEY }}
pull-request: true
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}