Skip to content

ACM-33139 Implement translation backporting mechanism#6099

Open
jeswanke wants to merge 6 commits intostolostron:mainfrom
jeswanke:ACM-33139-Implement-translation-backporting-mechanism
Open

ACM-33139 Implement translation backporting mechanism#6099
jeswanke wants to merge 6 commits intostolostron:mainfrom
jeswanke:ACM-33139-Implement-translation-backporting-mechanism

Conversation

@jeswanke
Copy link
Copy Markdown
Contributor

@jeswanke jeswanke commented May 5, 2026

📝 Summary

We're absolutely delighted to present the new frontend/i18n-scripts/translation-backporting.ts script

you can start it like this:

npm run i18n-backporting or
npm run i18n-backporting release-2.5

  1. the first part of this script verifies or prompts for the release to backport

  2. then list of all available releases before the target release is created:
    'upstream/release-2.16' << target
    'upstream/release-2.17'
    'upstream/release-5.0' << latest

  3. then starting with the target release:
    a. use git to get the english translation.json for it and the next one down (2.17)
    b. compare key/value pairs between 2.16 and 2.17
    (1) if they are exactly the same, use this key to continue with the other languages:
    (2) else check to see if they are similar--perhaps the english was simply polished
    --to check if they are similar, use the getSimularity function to see how far apart they are:

    in this example the strings are 0.97 similar (an s was added) so also use this key
    upstream/release-2.16: The following disk will not be included in the snapshot
    upstream/release-2.17: The following disks will not be included in the snapshot
    similarity: 0.9725

    in this example it's further apart--so user is prompted whether to use this key
    upstream/release-2.16: Associated Placements or PlacementRules
    upstream/release-2.17: Associated Placements
    similarity: 0.6897

    c. iterate thru languages using this key and when values don't match between 2.17 and 2.16, backport 2.17 to 2.16

  4. create pr for the changesz:
    a. create a worktree
    b. create a new branch in worktree
    c. use fs to copy the changes translation files into that worktree's branch
    d. stage the changes
    e. commit the changes
    f. push the changes
    g. use the github gh cli to create a pr
    h. remove the worktree

Ticket Summary (Title):
ACM-33139 Implement translation backporting mechanism

Ticket Link:
https://redhat.atlassian.net/browse/ACM-33139

Type of Change:

  • 🐞 Bug Fix
  • ✨ Feature
  • 🔧 Refactor
  • 💸 Tech Debt
  • 🧪 Test-related
  • 📄 Docs

✅ Checklist

General

  • PR title follows the convention (e.g. ACM-12340 Fix bug with...)
  • Code builds and runs locally without errors
  • No console logs, commented-out code, or unnecessary files
  • All commits are meaningful and well-labeled
  • All new display strings are externalized for localization (English only)
  • (Nice to have) JSDoc comments added for new functions and interfaces

If Feature

  • UI/UX reviewed (if applicable)
  • All acceptance criteria met
  • Unit test coverage added or updated
  • Relevant documentation or comments included

If Bugfix

  • Root cause and fix summary are documented in the ticket (for future reference / errata)
  • Fix tested thoroughly and resolves the issue
  • Test(s) added to prevent regression

🗒️ Notes for Reviewers

Summary by CodeRabbit

  • Chores
    • Added translation backporting CLI utility for managing translation updates across release branches with interactive selection and automated similarity matching
    • Configured ESLint with dedicated TypeScript settings for i18n scripts
    • Added development dependencies to support the translation workflow

Signed-off-by: John Swanke <jswanke@redhat.com>
Signed-off-by: John Swanke <jswanke@redhat.com>
Signed-off-by: John Swanke <jswanke@redhat.com>
Signed-off-by: John Swanke <jswanke@redhat.com>
@openshift-ci
Copy link
Copy Markdown

openshift-ci Bot commented May 5, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jeswanke

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci Bot added the approved label May 5, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 5, 2026

📝 Walkthrough

Walkthrough

Adds a TypeScript CLI (frontend/i18n-scripts/translation-backporting.ts) to backport translation changes between release refs, a tsconfig and ESLint override for the i18n-scripts directory, and package.json entries (script + devDependencies) to run the CLI.

Changes

Translation Backporting CLI

Layer / File(s) Summary
Compiler & Linting config
frontend/i18n-scripts/tsconfig.json, frontend/eslint.config.mjs
New tsconfig for i18n-scripts (ES2022, NodeNext, relaxed strictness). ESLint override added for i18n-scripts/**/*.ts pointing parserOptions.project to ./i18n-scripts/tsconfig.json with projectService: false.
Tooling / Scripts
frontend/package.json
Added i18n-backporting npm script (tsx i18n-scripts/translation-backporting.ts) and devDependencies: inquirer, simple-git, tsx.
Core CLI flow (entry & orchestration)
frontend/i18n-scripts/translation-backporting.ts (top-level run & control flow)
New CLI entry that fetches upstream refs, enumerates/sorts release branches, resolves target release (CLI arg / env var / interactive), and coordinates retrieval, diffing, prompting, worktree branch creation, commit/push, optional PR creation, and cleanup.
Translation retrieval & parsing
frontend/i18n-scripts/translation-backporting.ts (retrieveTranslations, release helpers)
Loads per-locale translation.json from arbitrary git refs using git show, with path validation and plural _0 fallback handling for ja/ko/zh. Includes release parsing/sorting and ref selection helpers.
Diffing, similarity & decision logic
frontend/i18n-scripts/translation-backporting.ts (getStringSimilarity, en backport logic, per-locale map diffing)`
Implements bigram-based dice-coefficient getStringSimilarity, determines EN backports using similarity thresholds, records per-locale differences, and applies interactive/non-TTY prompting rules for acceptance.
Output formatting & summary
frontend/i18n-scripts/translation-backporting.ts (printBackportKeyCountsTable, printBackportMapFormatted, helpers)
Formats and prints locale/key summary table and optional per-locale diffs (includes similarity scoring and clipped lines).
Worktree / git operations & PR creation
frontend/i18n-scripts/translation-backporting.ts (worktree creation, branch naming, commit/push, gh PR)`
Creates temporary git worktree, branches, writes updated frontend/public/locales/<lang>/translation.json, stages/commits/pushes, optionally creates PR via gh, and always removes the worktree.
API export
frontend/i18n-scripts/translation-backporting.ts
Exports getStringSimilarity(str1, str2, substringLength = 2, caseSensitive = false): number.

Sequence Diagram

sequenceDiagram
  participant User
  participant CLI as i18n-backporting CLI
  participant Git as Git (local/remote)
  participant FS as Filesystem
  participant GH as GitHub (gh)

  User->>CLI: invoke (arg/env/interactive)
  CLI->>Git: fetch upstream refs
  CLI->>Git: git show <ref>:frontend/public/locales/*/translation.json
  Git-->>CLI: translation file blobs
  CLI->>CLI: compute diffs & getStringSimilarity
  CLI->>User: prompt accept/backport? (TTY) 
  User-->>CLI: accept/reject
  CLI->>FS: create temp worktree, write updated locale files
  CLI->>Git: git add/commit/push branch
  CLI->>GH: optionally gh pr create (target base)
  GH-->>CLI: PR URL
  CLI->>FS: remove worktree, cleanup
  CLI-->>User: exit (summary/PR link)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 68.42% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive PR description includes ticket summary, link, type (Tech Debt), and detailed functional breakdown of the backporting script, but most checklist items remain unchecked despite being applicable. Verify and check applicable checklist items (code builds locally, no console logs, meaningful commits, JSDoc for new functions) to confirm readiness. Clarify coverage of acceptance criteria and testing.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'ACM-33139 Implement translation backporting mechanism' clearly and concisely summarizes the main change: adding a translation backporting script and mechanism.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🧹 Nitpick comments (1)
frontend/i18n-scripts/translation-backporting.ts (1)

6-7: 💤 Low value

Drop dead commented imports.

Proposed cleanup
 import inquirer from 'inquirer'
-// import readline from 'node:readline'
-// import tty from 'node:tty'
 import { simpleGit, type SimpleGit } from 'simple-git'
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@frontend/i18n-scripts/translation-backporting.ts` around lines 6 - 7, Remove
the dead commented import lines for "readline" and "tty" in
translation-backporting.ts: delete the two commented lines "// import readline
from 'node:readline'" and "// import tty from 'node:tty'" so the file contains
only active imports and no stale commented code.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@frontend/i18n-scripts/translation-backporting.ts`:
- Around line 590-602: The loop that builds translationMap currently assumes
git.show(spec) and JSON.parse(raw) always succeed, so a missing file or
malformed JSON at releaseRef will abort the whole backport; wrap the per-lang
retrieval inside a try/catch around git.show(spec) and JSON.parse(raw) (the code
referencing localeLangs, translationPath, git.show(spec), and
translationMap[lang]) and on error log a warning including lang and spec, then
either skip the lang or record a sentinel (e.g., null or an empty object) in
translationMap[lang] so the backport continues; ensure the catch distinguishes
missing-file vs parse errors in the message for easier debugging.
- Around line 303-305: The runCmd helper currently builds a single shell string
and calls execSync(cmd, { stdio:'inherit' }), which allows argument-boundary
breaks and shell-injection; change runCmd to accept a command plus an argv array
(or replace execSync with child_process.spawnSync/execFile using an args array)
and call execSync/execFile with { cwd, stdio:'inherit', encoding:'utf8',
shell:false } so arguments are not shell-interpolated. Update every call site
that passes interpolated branch names/refs/paths to pass the command and each
argument as separate entries (e.g. replace "git checkout -b ${branch}" with
["git","checkout","-b", branch]) and for places that relied on shell globbing
(frontend/public/locales/*) switch to adding the directory path (e.g.
"frontend/public/locales") or let git handle the path without shell expansion.
Ensure runCmd signature and all callers (the functions invoking runCmd) are
updated consistently.
- Around line 695-702: The prompt uses an unsupported type 'select' with
inquirer.prompt which will fail at runtime; change the prompt type to a
legacy-supported selection type such as 'list' (or 'rawlist') in the
inquirer.prompt call that builds releaseRef (the block that maps pickChoices via
pickChoices.map(({ name: ref, value: ref }))). Ensure the prompt remains
otherwise identical so releaseRef is returned as before.
- Around line 169-279: The code currently only writes to payloadMap when
currentRef === releaseRef (inside the orderedReleases loop) while
backportMap/backportEnMap accumulate across all iterations, causing the summary
(printBackportKeyCountsTable) to report more changes than are actually written;
choose the intended behavior and implement it: either (A) narrow the summary to
only count keys present in payloadMap before calling
printBackportKeyCountsTable, or (B) make payloadMap accumulate across the whole
loop by removing the currentRef === releaseRef guard and updating payloadMap
(and payloadChanged) whenever you add entries to backportEnMap/backportMap
(ensure you handle en separately via backportEnMap and similarity logic),
referencing the variables/functions payloadMap, payloadChanged, backportMap,
backportEnMap, currentRef, releaseRef, orderedReleases, and
printBackportKeyCountsTable so the counts and written disk payload stay in sync.

---

Nitpick comments:
In `@frontend/i18n-scripts/translation-backporting.ts`:
- Around line 6-7: Remove the dead commented import lines for "readline" and
"tty" in translation-backporting.ts: delete the two commented lines "// import
readline from 'node:readline'" and "// import tty from 'node:tty'" so the file
contains only active imports and no stale commented code.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 10c7d47c-9163-4a00-8e40-fe74d49fd852

📥 Commits

Reviewing files that changed from the base of the PR and between 0c671d0 and 9e00596.

⛔ Files ignored due to path filters (1)
  • frontend/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (4)
  • frontend/eslint.config.mjs
  • frontend/i18n-scripts/translation-backporting.ts
  • frontend/i18n-scripts/tsconfig.json
  • frontend/package.json

Comment thread frontend/i18n-scripts/translation-backporting.ts
Comment thread frontend/i18n-scripts/translation-backporting.ts Outdated
Comment thread frontend/i18n-scripts/translation-backporting.ts
Comment thread frontend/i18n-scripts/translation-backporting.ts
jeswanke added 2 commits May 5, 2026 15:55
Signed-off-by: John Swanke <jswanke@redhat.com>
Signed-off-by: John Swanke <jswanke@redhat.com>
@jeswanke jeswanke requested a review from KevinFCormier May 5, 2026 20:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant