The GitHub Action
Run transglot on every push to your repository: upload new strings, wait for the translations, and commit the finished locale files back to the branch.
The transglot GitHub Action runs the CLI in a workflow. On each run it pushes your source strings, waits for the translation batch to finish, pulls the translated files, and commits them to the branch the workflow ran on. Reference it as transglot/transglot-action@v1; the v1 tag moves to each new release of the action.
Before you start
- Commit
transglot.jsonto the repository. Runnpx transglot@latest initin your checkout to write one, or see the configuration reference. - Create a deploy token with the push and pull abilities. With push alone the action uploads strings but cannot bring translations back. See Deploy tokens.
- Add the token as a repository secret named
TRANSGLOT_TOKEN, under Settings → Secrets and variables → Actions in GitHub. The token never goes in the workflow file.
Add the workflow
Create .github/workflows/transglot.yml:
name: transglot
on:
push:
branches: [main]
jobs:
localize:
runs-on: ubuntu-latest
permissions:
contents: write # the action commits pulled translations back to a branch
steps:
- uses: actions/checkout@v7
- uses: transglot/transglot-action@v1
with:
token: ${{ secrets.TRANSGLOT_TOKEN }}
url: https://api.transglot.aiThe project's Releases page shows the same workflow in its Connect & SDK view, under GitHub Action: "Drop this into .github/workflows/transglot.yml and add TRANSGLOT_TOKEN to your repo secrets."
permissions: contents: write is required for the default commit mode. Without it, the commit step fails with a 403 because the job's token is read-only.
A commit made with the workflow's own GITHUB_TOKEN does not start another workflow run, so committing translations to main does not trigger this workflow again. If main requires a status check, GitHub refuses this commit; use an artifact or a pull request instead.
Inputs
Prop
Type
The action accepts only these inputs. GitHub ignores an input the action does not declare and only prints a warning, so check the spelling if a setting seems to have no effect.
Outputs
| Output | Description |
|---|---|
batch_id | The id of the translation batch the push queued. Empty when nothing needed translating. |
files_changed | How many files the pull rewrote. 0 when every file was already up to date. |
What a run does
- Installs the CLI on Node.js 22, once per run.
- Pushes your source files (
transglot push, with--waitunlesswaitis"false"). With--wait, the step waits up to 600 seconds. - Pulls the translated files (
transglot pull). It pulls when the push succeeded, when the word limit held the batch back (your sources are still synced), and when the batch failed, because translations that did complete can still be pulled. After any other error it skips the pull. - Commits or uploads the pulled files, depending on
commit. Inbranchmode it stages only the files the pull wrote, commits asgithub-actions[bot]with the messagechore(i18n): sync translations from transglot, and pushes. When nothing changed, or every pulled file is ignored by.gitignore, it skips the commit. Inartifactmode it uploads them as an artifact namedtransglot-files. - Reports the result. The job fails with the worst CLI exit code of the push and the pull. Because this step runs last, a failed batch still commits the translations that finished and sets both outputs before the job turns red.
Examples
Block a merge on a refused row
Run the action on pull requests with commit: none, and add a last step that fails when a pulled file is missing a key:
name: transglot-check
on:
pull_request:
branches: [main]
jobs:
localize:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v7
- uses: transglot/transglot-action@v1
with:
token: ${{ secrets.TRANSGLOT_TOKEN }}
url: https://api.transglot.ai
commit: none
- name: Fail when a language is missing a key
run: |
status=0
for file in locales/*.json; do
missing="$(jq -r --slurpfile source locales/en.json \
'($source[0] | [paths(scalars)]) - [paths(scalars)] | map(join(".")) | .[]' "$file")"
if [ -n "$missing" ]; then
echo "::error file=$file::Missing keys:" $missing
status=1
fi
done
exit "$status"The last step assumes JSON files at locales/{locale}.json with English as the source, so change its paths to match your transglot.json. For another file format, compare the keys with a tool that reads that format.
Then require the check. In GitHub, go to Settings → Branches, add a branch protection rule for main, turn on Require status checks to pass before merging, and select localize, the name of the job. GitHub lists a check only after it has run, so open a pull request first. Turn on Do not allow bypassing the above settings so the rule also binds administrators. On a private repository, branch protection needs a paid GitHub plan.
With this in place:
- A refused row fails the run that queued it, with exit code 4, and GitHub refuses the merge with
Required status check "localize" is failing. - A re-run or a new commit does not retry the row, because its source string has not changed. The action queues nothing and passes, and the last step keeps the check red while the key is missing. Without that step, the check turns green with the row still refused.
- To clear the check, change the source string in the pull request, which queues a new batch. Or fix the cause, such as a glossary term, select Retry failed on the project's Runs page, and re-run the job.
commit: branch does not work with a required check. On a pull_request run it cannot push, and on a branch push its commit has no check, so the merge waits. See Troubleshooting.
Two things this workflow does not do:
- It commits nothing.
commit: noneleaves the pulled files in the runner's workspace. To get them after the merge, use an artifact or a pull request. - It does not wait for the merge to upload strings. Each run uploads the pull request's source strings to the project, and translating them uses words. Keys from a pull request you close stay in the project, and later pulls write them to your files.
push --sync-removalsfrom your default branch deletes them. It also deletes the keys of other open pull requests, and the next run of each adds them back.
Upload files as an artifact
Use commit: artifact when the branch is protected, or to review the files before they land:
name: transglot
on:
push:
branches: [main]
jobs:
localize:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: transglot/transglot-action@v1
with:
token: ${{ secrets.TRANSGLOT_TOKEN }}
commit: artifactThe run's summary page lists the transglot-files artifact. This mode needs no write permission.
Open a pull request with the translations
With commit: none the files stay in the workspace, so a later step can do anything with them. This workflow opens a pull request with a third-party action:
name: transglot
on:
push:
branches: [main]
jobs:
localize:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v7
- uses: transglot/transglot-action@v1
id: transglot
with:
token: ${{ secrets.TRANSGLOT_TOKEN }}
commit: none
- if: steps.transglot.outputs.files_changed != '0'
uses: peter-evans/create-pull-request@v8
with:
branch: transglot/translations
commit-message: "chore(i18n): sync translations from transglot"
title: Sync translations from transglotGitHub refuses to open the pull request until Allow GitHub Actions to create and approve pull requests is on, under Settings → Actions → General. A pull request opened this way starts no workflow run, so a required check waits until someone closes and reopens it.
Push now, pull on a schedule
Large batches can take longer than you want a merge job to run. Push without waiting on every merge, and pull on a schedule with the CLI's pull --wait, which waits for every active batch of the project:
name: transglot
on:
push:
branches: [main]
schedule:
- cron: "0 3 * * *"
jobs:
push-strings:
if: github.event_name == 'push'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: 22
- run: npx --yes transglot@0.5.1 push
env:
TRANSGLOT_TOKEN: ${{ secrets.TRANSGLOT_TOKEN }}
pull-translations:
if: github.event_name == 'schedule'
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: 22
- run: npx --yes transglot@0.5.1 pull --wait --timeout 1800
env:
TRANSGLOT_TOKEN: ${{ secrets.TRANSGLOT_TOKEN }}
- run: |
if [ -n "$(git status --porcelain)" ]; then
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add -A
git commit -m "chore(i18n): sync translations from transglot"
git push
fiSetting wait: "false" on the action is not the same: it pulls straight after pushing, before anything is translated. A locale with no translations yet then stops the pull, because pull refuses to overwrite an existing file with an empty one.
Use the outputs
- uses: transglot/transglot-action@v1
id: transglot
with:
token: ${{ secrets.TRANSGLOT_TOKEN }}
- if: steps.transglot.outputs.batch_id != ''
run: echo "Translated in batch ${{ steps.transglot.outputs.batch_id }}, ${{ steps.transglot.outputs.files_changed }} file(s) changed"Troubleshooting
| What you see | Cause and fix |
|---|---|
| A 403 when the action pushes the commit | The job's token is read-only. Add permissions: contents: write, or use commit: artifact. |
| Authentication errors in the log (exit code 2) | The TRANSGLOT_TOKEN secret is missing, misspelled, revoked or expired, or the token lacks push or pull. |
| A configuration error (exit code 1) | transglot.json is missing from the checkout, or a path in it matches no file. |
| The job reports a failed or cancelled batch (exit code 4) | The translations that did complete were still pulled and committed. Retry the failed strings from the project's Runs page. |
| The job reports the word limit (exit code 3) | Your sources were uploaded; only the translation was held back. Raise the limit or wait for the reset. |
| The job reports a timeout (exit code 5) | The batch was still running after 600 seconds. It finishes on its own; the next run pulls the result. |
| The run succeeds but commits nothing | Nothing changed since the last run, or the pulled files are ignored by .gitignore. |
| A setting has no effect | It is not one of the inputs above. GitHub ignores undeclared inputs. |
fatal: You are not currently on a branch. on a pull request run | A pull_request run checks out a merge commit with no branch, so commit: branch cannot push. The job fails even though the translations finished. Set commit: none. |
Required status check "localize" is expected after the action commits to a branch | The action's commit is now the head of the branch, and a GITHUB_TOKEN commit starts no workflow run, so that commit has no check. Run the check on pull_request with commit: none. |
GH006: Protected branch update failed when the action pushes | The branch requires a status check, and the action's commit has none. Use an artifact or a pull request. |
GitHub Actions is not permitted to create or approve pull requests | Turn on Allow GitHub Actions to create and approve pull requests under Settings → Actions → General. |
| A required check passes on a re-run with a row still refused | push queues nothing when the source string has not changed, so the action passes. Add the last step of the merge check. |
Exit codes
Read the CLI's exit code to tell a configuration mistake from a revoked token, a spent word limit or a failed translation, and react to each in your pipeline.
REST API overview
Call the transglot API from your own scripts and CI to push, pull, translate, check, publish and subscribe to events.