DocsCLI

CI and GitHub Action

Validate messages on every pull request and translate on merge, using the CLI in GitHub Actions or any CI system.

On this page

The CLI is built for non-interactive use: no prompts when there is no terminal or when CI is set, progress is printed as plain lines, and results can be emitted as JSON with --json. Exit codes are listed on the commands page.

A two-step pipeline

  1. On pull requests, run generic-translation validate. It needs no credentials, makes no API calls, and fails on invalid ICU, extraction errors, and translations that do not match their source.
  2. On merge to your main branch, run generic-translation translate with a project API key, then commit or publish the result.

Credentials in CI

Create a project API key with only the permissions the job needs, and store it as a CI secret named GENERIC_TRANSLATION_API_KEY.

generic-translation keys create --name "CI" --permissions translations:enqueue,translations:write

translations:enqueue is enough for generic-translation translate; --publish also needs translations:write. The project id is not secret: commit projectId in generic-translation.config.json or set GENERIC_TRANSLATION_PROJECT_ID. Pointing at a self-hosted API? Set GENERIC_TRANSLATION_API_URL. See Configuration.

Getting the CLI onto the runner

@generic-translation/cli is not published to npm yet, so npm install -D @generic-translation/cli does not work yet. Two ways to run the CLI in a job today:

  • The committed bundle. The generic-translation-cli repository commits action/dist/cli.cjs, a single-file build of the CLI with every dependency inlined. It needs only Node, no install:

    - uses: actions/checkout@v5
    - uses: actions/checkout@v5
      with: { repository: generic-translation/generic-translation-cli, path: .generic-translation-cli }
    - run: echo "GENERIC_TRANSLATION_BIN=$GITHUB_WORKSPACE/.generic-translation-cli/action/dist/cli.cjs" >> "$GITHUB_ENV"
    - run: node "$GENERIC_TRANSLATION_BIN" validate
  • Build it from source. Clone the Generic Translation repository in the job and build packages/core and packages/cli, then run node packages/cli/dist/cli.js.

Once the package is published, a devDependency makes this npx generic-translation validate. The workflows below use $GENERIC_TRANSLATION_BIN for whichever way you chose,. The first option above sets it for you.

Example workflow: validate and translate

name: i18n
on:
  pull_request:
  push:
    branches: [main]

jobs:
  validate:
    if: github.event_name == 'pull_request'
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5
      # ... make the CLI available as shown above ...
      - run: node "$GENERIC_TRANSLATION_BIN" validate

  translate:
    if: github.event_name == 'push'
    runs-on: ubuntu-latest
    permissions:
      contents: write
    env:
      GENERIC_TRANSLATION_API_KEY: ${{ secrets.GENERIC_TRANSLATION_API_KEY }}
    steps:
      - uses: actions/checkout@v5
      # ... make the CLI available as shown above ...
      - run: node "$GENERIC_TRANSLATION_BIN" translate --publish
      - name: Commit locale files and lock file
        run: |
          git config user.name "generic-translation-bot"
          git config user.email "generic-translation-bot@users.noreply.github.com"
          git add generic-translation.lock.json public/_generic-translation locales docs
          git diff --cached --quiet || (git commit -m "chore: update translations" && git push)

Adjust the git add paths to your output and files settings. If your app fetches translations from the CDN at runtime you do not need to commit locale files, but you should still commit generic-translation.lock.json.

The branch name is detected from GITHUB_HEAD_REF / GITHUB_REF_NAME, so pull request runs of translate would store translations under the PR branch rather than main.

Useful flags in CI

Flag Why
--strict (on validate) Also fail on warnings and on messages not yet translated in the committed locale files.
--dry-run Show what a run would send, without credentials being spent.
--json Machine-readable result on stdout.
--timeout <seconds> Give long jobs more than the default 600 seconds.
--ignore-errors Keep partial output instead of failing; usually not what you want in CI.

If a run times out the job keeps running on the server. Pick it up with generic-translation status <jobId> --watch and generic-translation download --job <jobId>.

The GitHub Action

The CLI repository ships a composite action at action/. It runs generic-translation translate and opens or updates a pull request with the changed locale files.

name: Translate
on:
  push:
    branches: [main]
  workflow_dispatch:

permissions:
  contents: write
  pull-requests: write

jobs:
  translate:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5
      - uses: generic-translation/generic-translation-cli/action@main
        with:
          api-key: ${{ secrets.GENERIC_TRANSLATION_API_KEY }}
          project-id: ${{ vars.GENERIC_TRANSLATION_PROJECT_ID }} # optional if generic-translation.config.json has projectId

It does not need npm. By default the action runs dist/cli.cjs, the self-contained bundle committed next to action.yml. Only the optional cli-version input (which runs npx @generic-translation/cli@<version>) needs the published package, which does not exist yet.

Status. The action has been exercised in a real workflow run against the live API: both the translate job and the open-a-pull-request job passed. That is one end-to-end run, not a guarantee for every repository layout.

Each run commits the result to generic-translation/translations-<branch> and opens or updates a pull request into that branch. Translations are stored under the branch being built, so a run on a feature branch does not overwrite main’s strings. Your repository may block Actions from creating pull requests (Settings, Actions, General, “Allow GitHub Actions to create and approve pull requests”); enable it, or pass a personal access token as github-token.

Input Default Purpose
api-key required Project API key. Needs translations:enqueue and project:read; add files:read + files:write for the files config and translations:write to publish.
project-id empty Project id; optional when set in generic-translation.config.json.
config generic-translation.config.json Path to the config, relative to the repository root. Paths inside it are relative to the config file, so a monorepo can point at apps/web/generic-translation.config.json.
publish empty true / false to publish to the CDN after translating. Empty uses the config value.
branch-prefix generic-translation/translations- The pull request branch is this prefix plus the current branch name.
locales empty Comma-separated target locales overriding the config.
args empty Extra generic-translation translate flags, for example --ignore-errors --timeout 1200.
api-url empty API base URL. Empty uses the hosted API.
cli-version empty Empty runs the bundled CLI. A version or dist-tag runs npx @generic-translation/cli@<version> instead.
node-version 22 Node.js version to set up. Empty uses the runner’s Node.
create-pr true false leaves the files in the workspace, so you can commit them or upload them as an artifact.
pr-title, commit-message chore(i18n): update translations
github-token ${{ github.token }} Token for pushing and opening the pull request.

Outputs: changed ("true" when any file changed), pr-url, pr-number, result (the JSON from generic-translation translate --json).

Extraction errors fail the step with file:line:col messages (exit code 1); pass args: --ignore-errors to skip broken messages instead.

Without any CI: the GitHub agent

If you would rather not maintain a workflow, the GitHub agent does the same job from the Generic Translation side. It needs a GitHub App that the instance owner has to register, and that is not set up on the hosted instance today.

Something wrong or unclear on this page? Open an issue.

Type to search the documentation.