Trim Related I18n Diffs

Use this skill when a commit range in one Simplified Chinese language file is the source of truth, and the task is to keep only the current uncommitted changes in sibling i18n files that correspond to those real changes.

Typical requests:

Goal

Turn a noisy set of uncommitted i18n edits into a focused diff that keeps only the changes that are semantically tied to a baseline file's real modifications.

Inputs To Identify

Gather these inputs before editing:

If the user does not say otherwise, assume the baseline file is only used for analysis and you should trim the other currently modified sibling language files in the same directory.

Workflow

1. Inspect the baseline diff

Run a diff for the baseline file over the requested range and determine the real changed keys.

Preferred command pattern:

git diff <range> -- <baseline-file>

Do not rely on line numbers alone. Treat these as the real changes:

When reading the patch, extract the i18n keys from changed object entries, for example lines that look like:

'reset' : '重置',

2. Build the relevant key set

Create the smallest possible key set from the baseline diff.

Include:

Do not include unrelated neighbors just because they share nearby line numbers.

3. Find the uncommitted candidate files

List the currently modified sibling language files in the same directory as the baseline file and narrow to the intended scope.

Preferred command pattern:

git diff --name-only -- <baseline-dir>/*.js
git status --short

Usually this means:

all `*.js` language files in the same directory as the chosen `*_zh_CN.js`

Selection rules:

4. Trim each target file against HEAD

For each modified target file:

This is the important rule:

That means the output file should effectively be:

5. Handle add, remove, rename correctly

Key-specific handling:

Do not reorder the whole file unless the file was already reordered. Prefer minimal diffs.

6. Verify the trimmed result

After editing, verify that the remaining diff is limited to the relevant key set.

Recommended checks:

The remaining hunks should only touch keys from the relevant key set. If unrelated strings like search, AI, or text mode keys remain, the trim was too broad and should be corrected.

Safe Editing Rules

Practical Strategy

For many sibling language files, scripting the trim is safer than manual editing.

A reliable approach is:

  1. Extract relevant keys from the baseline range diff
  2. Read each target file from HEAD
  3. Read each target file from working tree
  4. Rebuild the output from HEAD, overlaying only relevant key changes from the working tree
  5. Write back only if the rebuilt file differs from the current working tree

This approach is especially useful when many language files contain mixed relevant and irrelevant edits.

Output Expectations

When reporting back to the user, summarize:

Example Fit

This skill is a strong fit for workflows like:

Where the goal is to keep only the still-uncommitted translation changes in sibling files that truly map to the baseline file's changed keys.