@diglot/action
v0.2.2
Published
GitHub Action that keeps diglot translations in sync with their sources
Readme
@diglot/action
A GitHub Action for diglot translations repositories. On each run it extracts every source, diffs it against the stored manifests, machine-translates what changed for each locale with machine translation enabled, rebuilds dist/<locale>.json (unless build-dist is false), and commits the result as one commit.
- uses: actions/checkout@v4
- id: diglot
uses: danielroe/diglot/packages/action@main
with:
git-user-name: translations-bot
git-user-email: [email protected]
env:
AI_GATEWAY_API_KEY: ${{ secrets.AI_GATEWAY_API_KEY }}
- if: steps.diglot.outputs.committed == 'true'
run: git pull --rebase origin ${{ github.ref_name }} && git push
env:
GIT_COMMITTER_NAME: translations-bot
GIT_COMMITTER_EMAIL: [email protected]The Action commits to the checked-out branch and never pushes; pushing is the workflow's step, so the job needs contents: write and no other token. See examples/nuxt for a complete translations repository and workflow.
What a run does
- Loads
diglot.config.tsandsources.yml. Sources with arepoand arefwhosepathdoes not exist (default.diglot/checkouts/<repo>) are fetched shallowly into a bare repository; existing working copies are read as they are. - Extracts the segments of each source at its
refand diffs them file by file against.diglot/manifest/<source>.json. Modified segments are paired with their predecessor; the pairing is kept in.diglot/lineage.jsonso a later run can still find it. - For each locale whose
<locale>/locale.ymlhasmt.enabled: true, every live segment without a record is handled once (identical text across sources and branches shares one record):- with a predecessor whose record is not rejected:
updateTranslationfrom@diglot/mt, which carries the text over without a model call when the skeleton is identical and only the hash changed (a context salt,derived: carry), and otherwise updates it from the word diff (derived: update), case and punctuation edits included; - otherwise:
translateSegments, one request per page, with the locale's glossary and style.
- with a predecessor whose record is not rejected:
- Writes records with
review: noneandprevwhere there is a predecessor (origin: mt, except carries, which keep the predecessor'soriginandmt; carried and updated records read aspending-review), updates manifests, and, unlessbuild-distisfalse, buildsdist/<locale>.jsonfrom the live records of every locale. - Commits the changed records and state (and the bundles, when
build-distis notfalse) as the given identity with a summary message, for examplechore(fr): translate 78 segments, update 12, carry 31.
Records a reviewer rejected (review: rejected) are kept as they are and shipped in the bundles, so their segments are not translated again until their source changes. Segments rejected by QA are listed in .diglot/rejected/<locale>.json with the reasons and skipped by later runs until their source changes (or retry-rejected is set). Locales with machine translation disabled get no new records, but their bundles are still rebuilt when build-dist is not false. A run with no source changes makes no model calls and no commit.
Inputs
| Input | Default | Description |
| --- | --- | --- |
| working-directory | . | Root of the translations repository |
| locales | all | Only these locales (comma or space separated) |
| sources | all | Only these sources |
| model | mt.model, then DIGLOT_MT_MODEL | Model id for the Vercel AI Gateway |
| ai-gateway-api-key | AI_GATEWAY_API_KEY | Gateway key |
| limit | none | Most segments per locale sent to the model in one run; the rest wait for the next run |
| retry-rejected | false | Translate previously rejected segments again |
| commit | true | Commit the changes |
| build-dist | true | Build dist/<locale>.json and add it to the commit |
| git-user-name | diglot[bot] | Commit author |
| git-user-email | diglot[bot]@users.noreply.github.com | Commit author email |
Outputs
| Output | Description |
| --- | --- |
| translated | Segments translated from scratch |
| updated | Translations updated from their predecessor |
| carried | Translations carried over from their predecessor |
| rejected | Segments rejected by QA |
| costUsd | Model cost in USD, when the provider reports it |
| committed | true when a commit was made |
| sha | The new commit |
The job summary has a table per locale and source, and the segments rejected by QA with their issues. Its Skipped column counts the live segments of each locale whose record a reviewer rejected.
As a library
import { run, summary } from '@diglot/action'
const result = await run({ cwd: '.', locales: ['fr'], limit: 200, commit: false })
console.log(summary(result))