Key points
- Use pull_request with its default activity types and a paths filter so the job runs only when message files or the code using them change
- Declare only the permissions you need; once you declare any, the rest are set to none
- Pull requests from forks get a read-only GITHUB_TOKEN and no other secrets
- Annotations (::error) and the job summary show which keys are wrong, directly on the pull request
Why check translations in CI
Translation problems are usually found late: the day before a release, or when a Japanese customer sends a screenshot. Yet many of them are mechanical. A missing key, an empty value or a misspelled placeholder can be found by a script. If that script runs in the same pull request that changed the strings, the person who made the change still remembers the context and can fix it in minutes. This article builds such a check with GitHub Actions, following GitHub's official documentation.
Decide when the workflow runs
According to GitHub's docs, a pull_request workflow runs by default only when the activity type is opened, synchronize or reopened: when the pull request is opened, when commits are pushed to it, and when it is reopened. Adding a paths filter narrows this further. If at least one changed path matches a pattern in the filter, the workflow runs. Limiting it to message files and the code that uses them keeps unrelated pull requests fast.
Grant only the permissions you need
The permissions key controls what the GITHUB_TOKEN can do. The docs state that if you specify the access for any permission, all permissions you do not specify are set to none. A check that only reads files needs contents: read. If a tool will post comments or suggestions on the pull request, add pull-requests: write.
name: i18n
on:
pull_request:
paths:
- 'messages/**'
- 'app/**'
- 'components/**'
permissions:
contents: read
jobs:
keys:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
- run: node scripts/check-keys.mjsThe script referenced here can be as simple as the key comparison in our guide on key parity: flatten both JSON files, compare the key sets, and exit with a non-zero code when keys are missing. Keep it runnable locally with the same command, so developers can reproduce a CI failure on their own machine.
It also helps to expose the script as an npm script, for example npm run i18n:check, and to mention it in the contributing guide. Translators and reviewers who do not work on the code every day can then run exactly what CI runs before they push, and the CI job becomes a safety net rather than the first place problems appear.
Show results on the pull request
If findings live only in the log, nobody reads them. GitHub Actions workflow commands let a script create annotations by printing specially formatted lines to standard output. There are three levels, ::error, ::warning and ::notice, and each accepts file, line, endLine, col, endColumn and title. If line is omitted it defaults to 1. Each command creates an annotation that can be associated with a particular file in the repository, so the finding is tied to ja.json rather than buried in the log.
for (const key of missing) {
console.log(`::error file=messages/ja.json,title=Missing key::${key} is missing from ja.json`);
}
for (const key of extra) {
console.log(`::warning file=messages/ja.json,title=Extra key::${key} is not in en.json`);
}When there are many findings, a table in the job summary is easier to read. Append Markdown to the file whose path is in the GITHUB_STEP_SUMMARY environment variable, and it is shown on the workflow run's summary page. The docs limit each step's summary to 1 MiB and display at most 20 step summaries per job.
import fs from 'node:fs';
const rows = missing.map((k) => `| ${k} | missing |`).join('\n');
fs.appendFileSync(
process.env.GITHUB_STEP_SUMMARY,
`### ja.json check\n\n| Key | State |\n| --- | --- |\n${rows}\n`
);Pull requests from forks
Open-source projects receive pull requests from forks, and those run with reduced rights. GitHub's docs say that in pull requests from forked repositories the GITHUB_TOKEN has read-only permissions, and that, with the exception of GITHUB_TOKEN, secrets are not passed to the runner. Any step that comments on the pull request or calls an API with a secret key will fail there. Design the workflow so that, in that case, results are reported only through annotations and the job summary, and the job does not fail just because it could not comment.
The pull_request_target event can give fork pull requests a write token, but GitHub documents its risks on a separate page, Securely using pull_request_target, which warns against checking out, building or running code from an untrusted pull request in such workflows. Read it before using that event for translation checks.
Let reviewers apply fixes in one click
Suggested changes in a pull request review can be applied directly in the pull request by anyone with write access to the repository. Click Commit suggestion to apply one change in its own commit, or add several to a batch and click Commit suggestions. Either way a single commit is created on the pull request's compare branch, and everyone who suggested a change included in it becomes a co-author. If a checker posts its fixes as suggestions, a translator can accept them without opening ja.json at all.
Decide how strict each check is
Not every finding should block a merge. A useful rule of thumb is to fail the build only for problems that users would see as broken, and to warn about everything else. The table shows one way to split them.
| Check | Severity | Reason |
|---|---|---|
| Missing key, empty translation | error (fail) | A raw key or nothing appears on screen |
| Placeholder mismatch, broken ICU | error (fail) | A value disappears or formatting throws |
| Extra key | warning | Nothing breaks on screen |
| Spelling variants, mixed style | warning | Whether to fix depends on your style rules |
Script the check
Make it run with the same command locally and in CI.
Add the workflow
Trigger on pull_request with paths, and declare only the permissions you need.
Report on the pull request
Use ::error and GITHUB_STEP_SUMMARY to show which keys are wrong.
Return fixes as suggestions
Where the fix is known, post it in a form reviewers can commit with one click.
Once this is in place, translation quality becomes part of normal code review rather than a separate task before each release. The same pattern works for any language you add later.
FAQ
Should the check run on push or on pull_request?
Use pull_request to show results on the pull request. Running it on pushes to main as well also covers changes that reach main without a pull request.
How do we get line numbers for annotations?
You need a JSON reader that keeps track of line numbers. JSON.parse does not return position information, so either count lines while reading or use a tool that reports them.
Can the same workflow check other languages?
Yes. Pass the target file as an argument to the script, or loop over every file in the messages folder, and compare each one with the source file. Plural rules differ by language, so group plural keys per language before comparing.
Will annotations work on pull requests from forks?
Annotations come from the job's own output, so they do not need a write token. That is why they are a good fallback when commenting is not possible.
How YakuCheck helps
The YakuCheck GitHub Action checks key parity, placeholders, typical UI mistranslations, spelling variants and style, and reports them as annotations, one summary comment on the pull request and suggestions on changed lines that can be applied with Commit suggestion. The fail-on input chooses which severity fails the job (error, warning or never).
When it cannot write, as on pull requests from forks, it does not fail the job and reports through annotations and the job summary instead. The CLI can output text, json, sarif, github or markdown. Rule checks send nothing outside your CI.
Sources
- GitHub Docs: Events that trigger workflows (pull_request)
- GitHub Docs: Workflow syntax for GitHub Actions (paths, permissions)
- GitHub Docs: Workflow commands for GitHub Actions (error, warning, notice, job summary)
- GitHub Docs: Incorporating feedback in your pull request
- GitHub Docs: Securely using pull_request_target
Last checked
Library behavior changes between versions. Check the official documentation for the version you use.