Skip to content

[diffs] Add a labels option for localizing diff text - #1271

Merged
amadeus merged 9 commits into
pierrecomputer:beta-1.7from
unknwon:jc/diffs-labels
Nov 8, 2026
Merged

amadeus merged 9 commits into
pierrecomputer:beta-1.7from
unknwon:jc/diffs-labels

Conversation

@unknwon

@unknwon unknwon commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Description

Adds a labels option to diff options (and CodeView) for the user-visible text the diff renders:

interface DiffLabels {
  unmodifiedLines: (count: number) => string; // "12 unmodified lines"
  unknownUnmodifiedLines: string; // "More unchanged context may be available"
  expandAll: string; // "Expand all"
  noNewlineAtEndOfFile: string; // "No newline at end of file"
}

labels?: Partial<DiffLabels>;
  • Every label is optional and falls back to its English default from the new DEFAULT_DIFF_LABELS export, so existing output is unchanged. An explicit undefined also falls back.
  • unmodifiedLines takes the count so callers can apply their own plural rules. The English default keeps the existing Intl.PluralRules('en-US') logic.
  • Labels are resolved in getOptionsWithDefaults() and carried on the render context to createSeparator and createNoNewlineElement. labels is added to getDiffHunksRendererOptions and CODE_VIEW_DIFF_OPTION_KEYS so it reaches the renderer from FileDiff and from CodeView items. SSR picks it up through the existing options spread.
  • No cache invalidation is needed. Separators and no-newline rows are rebuilt from the cached highlight on every render, and areOptionsEqual already compares labels by reference, like hunkSeparators. A new labels object therefore re-renders, and the docs note that callers should keep it stable.

Motivation & Context

These strings are hard-coded in English inside the shadow root, so apps that localize their UI cannot translate them. In Gogs we currently walk every shadow root with a MutationObserver and rewrite the text after each render, which shows English until the observer runs and breaks whenever the source strings change.

A companion PR added the same option to @pierre/trees (#1272, merged).

Type of changes

  • Bug fix (non-breaking change which fixes an issue)
  • Refactoring (non-breaking change)
  • New feature (non-breaking change which adds functionality). You must have
    first discussed with the dev team and they should be aware that this PR is
    being opened
  • Breaking change (fix or feature that would change existing functionality).
    You must have first discussed with the dev team and they should be aware
    that this PR is being opened
  • Documentation update

Checklist

  • I have read the
    contributing guidelines
  • My code follows the code style of the project (moon run root:lint)
  • My code is formatted properly (moon run root:format)
  • I have updated the documentation accordingly (if applicable)
  • I have added tests to cover my changes (if applicable)
  • All new and existing tests pass (moonx diffs:test)

The "Build, test, lint" CI job passes, including the four new tests in DiffHunksRender.test.ts.

How was AI used in generating this PR

Drafted with Claude Code (Claude Opus 5.5), including the code, tests, docs, and this description.

Related issues

None filed. Companion PR for @pierre/trees: #1272.

@vercel

vercel Bot commented Nov 7, 2026

Copy link
Copy Markdown

@unknwon is attempting to deploy a commit to the Pierre Computer Company Team on Vercel.

A member of the Team first needs to authorize it.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-08T07:19:19.995759Z acbc108 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d2b705fe36

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

unknwon and others added 7 commits November 7, 2026 22:58
Apps that translate their UI cannot change the English text the diff
renders, such as "12 unmodified lines" or "Expand all". This adds a
package-level `i18n` singleton the app configures once at boot, on the
server and the client, instead of passing text through component
options.

Translations are plain ICU MessageFormat strings, so one JSON config
serves both sides of the server/client boundary. The formatter supports
only what the strings need: `{name}` arguments and one plural block per
string with the CLDR categories, selected through `Intl.PluralRules`
for the configured locale. No dependencies are added.

`DEFAULT_TRANSLATIONS` defines the keys and the English templates;
`DiffsTranslations` is derived from it. `i18n.set()` replaces every
translation and the locale, falls back to English for anything left
out, validates and compiles before changing state, and notifies
subscribers only on a real change. Nothing reads the store yet; the
renderer and component subscriptions follow.
Hunk separators and the no-newline marker now take their text from the
`i18n` singleton. The `labels` diff option, its `DiffLabels` type, the
`DEFAULT_DIFF_LABELS` defaults, the `resolveDiffLabels` helper, and the
hand-rolled English plural rule are removed; nothing is passed through
component options any more.

`createSeparator` and `createNoNewlineElement` call `i18n.t()`
themselves, so their signatures return to what they were before the
option existed. With the default English translations the rendered
output is unchanged.
Switch languages with `i18n.set()` while a diff is on screen and its
hunk separators, no-newline marker, and merge-conflict buttons now
update in place, like a theme change does. Before, new translations
only showed up on the next render for an unrelated reason.

`FileDiff` subscribes to the i18n store where it subscribes to theme
changes, unsubscribes in `cleanUp`, and handles the change with a
plain `rerender()`: separators and injected rows are rebuilt from the
cached highlight on every forced render, so no cache is cleared.
`VirtualizedFileDiff` and `UnresolvedFile` inherit it. `CodeView` does
not subscribe; its mounted items do, and recycled shells hold no
rendered rows.

The merge-conflict action buttons ("Accept current change", "Accept
incoming change", "Accept both") move into `DEFAULT_TRANSLATIONS` and
are read through `i18n.t()` at render time.
Add an Internationalization page: configuring `i18n.set()` once at boot
on server and client, switching languages at runtime from JSON files,
the supported ICU message subset with plural categories, the full key
table with English defaults, and the server-rendering rules. Register
the section with the llms.txt generator so the docs build includes it.

Remove the `labels` option from the React and Vanilla shared-options
examples, since that option no longer exists.
The search panel's placeholders, match status, option toggles, and
buttons were hard-coded English, so a translated app still showed an
English find-and-replace bar. They now come from `DEFAULT_TRANSLATIONS`
through `i18n.t()`, read when the panel is built, which happens on each
open.

The match count becomes a plural template, so a single match reads
"1 result" instead of "1 results". The docs key table lists the new
keys.
@vercel

vercel Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
pierre-diffshub Ready Ready Preview Nov 8, 2026 7:47am UTC
pierre-docs-diffs Ready Ready Preview Nov 8, 2026 7:47am UTC
pierre-docs-trees Ready Ready Preview Nov 8, 2026 7:47am UTC
pierrejs-diff-demo Ready Ready Preview Nov 8, 2026 7:47am UTC

Request Review

@amadeus

amadeus commented Nov 8, 2026

Copy link
Copy Markdown
Member

Alright, so looking at this holistically, i think the better architecture is to have a proper i18n singleton class instance that can handle all strings across the entire package so it doesn't pollute options or require a dev to continuously set these labels on new instances.

Also I made it so the strings follow the ICU MessageFormat, which enables languages to be SSR to Client Component compatible.

@amadeus

amadeus commented Nov 8, 2026

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Something went wrong. Try again later by commenting “@codex review”.

Failed to sample tokens
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@amadeus

amadeus commented Nov 8, 2026

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: acbc108448

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

CI ran `UnresolvedFile.sequentialResolve.test.ts` before `i18n.test.ts`
in one process. The first mounts an `UnresolvedFile` and never cleans
it up, so it stays subscribed to the i18n store, and the later
`i18n.set()` re-rendered it into a torn-down DOM. Three virtualized
hydration tests left rendered instances behind the same way. Each now
calls `cleanUp()` in its `finally`.

The search e2e test expected "1 results"; the panel now says
"1 result".
CI ran test files in an order where a `VirtualizedFileDiff` left mounted
by `virtualizedEditorViewport.test.ts` was still subscribed to the i18n
store when a later file called `i18n.set()`. The re-render threw into a
DOM that no longer existed and failed every translation test. Bun lists
files in filesystem order, which is alphabetical on macOS and arbitrary
on Linux, so the order never occurred locally.

Patching each leaking test is not reliable, so the DOM harness now
drops every subscriber and restores the English defaults on install and
on cleanup, the same way it already clears the render queue. The fake
DOM harness in `hydration.test.ts` does the same. `i18n.clearSubscribers`
is marked `@internal` for that purpose. The leaking test also cleans up
its instance.
@amadeus
amadeus merged commit fb9d610 into pierrecomputer:beta-1.7 Nov 8, 2026
8 checks passed
ije pushed a commit that referenced this pull request Nov 11, 2026
* [diffs] Add a labels option for localizing diff text

* feat(diffs): add an i18n store for user-visible diff text

Apps that translate their UI cannot change the English text the diff
renders, such as "12 unmodified lines" or "Expand all". This adds a
package-level `i18n` singleton the app configures once at boot, on the
server and the client, instead of passing text through component
options.

Translations are plain ICU MessageFormat strings, so one JSON config
serves both sides of the server/client boundary. The formatter supports
only what the strings need: `{name}` arguments and one plural block per
string with the CLDR categories, selected through `Intl.PluralRules`
for the configured locale. No dependencies are added.

`DEFAULT_TRANSLATIONS` defines the keys and the English templates;
`DiffsTranslations` is derived from it. `i18n.set()` replaces every
translation and the locale, falls back to English for anything left
out, validates and compiles before changing state, and notifies
subscribers only on a real change. Nothing reads the store yet; the
renderer and component subscriptions follow.

* refactor(diffs): read diff text from the i18n store

Hunk separators and the no-newline marker now take their text from the
`i18n` singleton. The `labels` diff option, its `DiffLabels` type, the
`DEFAULT_DIFF_LABELS` defaults, the `resolveDiffLabels` helper, and the
hand-rolled English plural rule are removed; nothing is passed through
component options any more.

`createSeparator` and `createNoNewlineElement` call `i18n.t()`
themselves, so their signatures return to what they were before the
option existed. With the default English translations the rendered
output is unchanged.

* fix(i18n): add strings for UnresolvedFile

* feat(diffs): re-render mounted diffs when translations change

Switch languages with `i18n.set()` while a diff is on screen and its
hunk separators, no-newline marker, and merge-conflict buttons now
update in place, like a theme change does. Before, new translations
only showed up on the next render for an unrelated reason.

`FileDiff` subscribes to the i18n store where it subscribes to theme
changes, unsubscribes in `cleanUp`, and handles the change with a
plain `rerender()`: separators and injected rows are rebuilt from the
cached highlight on every forced render, so no cache is cleared.
`VirtualizedFileDiff` and `UnresolvedFile` inherit it. `CodeView` does
not subscribe; its mounted items do, and recycled shells hold no
rendered rows.

The merge-conflict action buttons ("Accept current change", "Accept
incoming change", "Accept both") move into `DEFAULT_TRANSLATIONS` and
are read through `i18n.t()` at render time.

* docs(diffs): document the i18n store

Add an Internationalization page: configuring `i18n.set()` once at boot
on server and client, switching languages at runtime from JSON files,
the supported ICU message subset with plural categories, the full key
table with English defaults, and the server-rendering rules. Register
the section with the llms.txt generator so the docs build includes it.

Remove the `labels` option from the React and Vanilla shared-options
examples, since that option no longer exists.

* feat(diffs): read editor search panel text from the i18n store

The search panel's placeholders, match status, option toggles, and
buttons were hard-coded English, so a translated app still showed an
English find-and-replace bar. They now come from `DEFAULT_TRANSLATIONS`
through `i18n.t()`, read when the panel is built, which happens on each
open.

The match count becomes a plural template, so a single match reads
"1 result" instead of "1 results". The docs key table lists the new
keys.

* test(diffs): clean up mounted instances and expect the singular count

CI ran `UnresolvedFile.sequentialResolve.test.ts` before `i18n.test.ts`
in one process. The first mounts an `UnresolvedFile` and never cleans
it up, so it stays subscribed to the i18n store, and the later
`i18n.set()` re-rendered it into a torn-down DOM. Three virtualized
hydration tests left rendered instances behind the same way. Each now
calls `cleanUp()` in its `finally`.

The search e2e test expected "1 results"; the panel now says
"1 result".

* test(diffs): drop i18n subscribers when a test DOM is torn down

CI ran test files in an order where a `VirtualizedFileDiff` left mounted
by `virtualizedEditorViewport.test.ts` was still subscribed to the i18n
store when a later file called `i18n.set()`. The re-render threw into a
DOM that no longer existed and failed every translation test. Bun lists
files in filesystem order, which is alphabetical on macOS and arbitrary
on Linux, so the order never occurred locally.

Patching each leaking test is not reliable, so the DOM harness now
drops every subscriber and restores the English defaults on install and
on cleanup, the same way it already clears the render queue. The fake
DOM harness in `hydration.test.ts` does the same. `i18n.clearSubscribers`
is marked `@internal` for that purpose. The leaking test also cleans up
its instance.

---------

Co-authored-by: Amadeus Demarzi <[email protected]>
amadeus added a commit that referenced this pull request Nov 14, 2026
* [diffs] Add a labels option for localizing diff text

* feat(diffs): add an i18n store for user-visible diff text

Apps that translate their UI cannot change the English text the diff
renders, such as "12 unmodified lines" or "Expand all". This adds a
package-level `i18n` singleton the app configures once at boot, on the
server and the client, instead of passing text through component
options.

Translations are plain ICU MessageFormat strings, so one JSON config
serves both sides of the server/client boundary. The formatter supports
only what the strings need: `{name}` arguments and one plural block per
string with the CLDR categories, selected through `Intl.PluralRules`
for the configured locale. No dependencies are added.

`DEFAULT_TRANSLATIONS` defines the keys and the English templates;
`DiffsTranslations` is derived from it. `i18n.set()` replaces every
translation and the locale, falls back to English for anything left
out, validates and compiles before changing state, and notifies
subscribers only on a real change. Nothing reads the store yet; the
renderer and component subscriptions follow.

* refactor(diffs): read diff text from the i18n store

Hunk separators and the no-newline marker now take their text from the
`i18n` singleton. The `labels` diff option, its `DiffLabels` type, the
`DEFAULT_DIFF_LABELS` defaults, the `resolveDiffLabels` helper, and the
hand-rolled English plural rule are removed; nothing is passed through
component options any more.

`createSeparator` and `createNoNewlineElement` call `i18n.t()`
themselves, so their signatures return to what they were before the
option existed. With the default English translations the rendered
output is unchanged.

* fix(i18n): add strings for UnresolvedFile

* feat(diffs): re-render mounted diffs when translations change

Switch languages with `i18n.set()` while a diff is on screen and its
hunk separators, no-newline marker, and merge-conflict buttons now
update in place, like a theme change does. Before, new translations
only showed up on the next render for an unrelated reason.

`FileDiff` subscribes to the i18n store where it subscribes to theme
changes, unsubscribes in `cleanUp`, and handles the change with a
plain `rerender()`: separators and injected rows are rebuilt from the
cached highlight on every forced render, so no cache is cleared.
`VirtualizedFileDiff` and `UnresolvedFile` inherit it. `CodeView` does
not subscribe; its mounted items do, and recycled shells hold no
rendered rows.

The merge-conflict action buttons ("Accept current change", "Accept
incoming change", "Accept both") move into `DEFAULT_TRANSLATIONS` and
are read through `i18n.t()` at render time.

* docs(diffs): document the i18n store

Add an Internationalization page: configuring `i18n.set()` once at boot
on server and client, switching languages at runtime from JSON files,
the supported ICU message subset with plural categories, the full key
table with English defaults, and the server-rendering rules. Register
the section with the llms.txt generator so the docs build includes it.

Remove the `labels` option from the React and Vanilla shared-options
examples, since that option no longer exists.

* feat(diffs): read editor search panel text from the i18n store

The search panel's placeholders, match status, option toggles, and
buttons were hard-coded English, so a translated app still showed an
English find-and-replace bar. They now come from `DEFAULT_TRANSLATIONS`
through `i18n.t()`, read when the panel is built, which happens on each
open.

The match count becomes a plural template, so a single match reads
"1 result" instead of "1 results". The docs key table lists the new
keys.

* test(diffs): clean up mounted instances and expect the singular count

CI ran `UnresolvedFile.sequentialResolve.test.ts` before `i18n.test.ts`
in one process. The first mounts an `UnresolvedFile` and never cleans
it up, so it stays subscribed to the i18n store, and the later
`i18n.set()` re-rendered it into a torn-down DOM. Three virtualized
hydration tests left rendered instances behind the same way. Each now
calls `cleanUp()` in its `finally`.

The search e2e test expected "1 results"; the panel now says
"1 result".

* test(diffs): drop i18n subscribers when a test DOM is torn down

CI ran test files in an order where a `VirtualizedFileDiff` left mounted
by `virtualizedEditorViewport.test.ts` was still subscribed to the i18n
store when a later file called `i18n.set()`. The re-render threw into a
DOM that no longer existed and failed every translation test. Bun lists
files in filesystem order, which is alphabetical on macOS and arbitrary
on Linux, so the order never occurred locally.

Patching each leaking test is not reliable, so the DOM harness now
drops every subscriber and restores the English defaults on install and
on cleanup, the same way it already clears the render queue. The fake
DOM harness in `hydration.test.ts` does the same. `i18n.clearSubscribers`
is marked `@internal` for that purpose. The leaking test also cleans up
its instance.

---------

Co-authored-by: Amadeus Demarzi <[email protected]>
amadeus added a commit that referenced this pull request Nov 21, 2026
* [diffs] Add a labels option for localizing diff text

* feat(diffs): add an i18n store for user-visible diff text

Apps that translate their UI cannot change the English text the diff
renders, such as "12 unmodified lines" or "Expand all". This adds a
package-level `i18n` singleton the app configures once at boot, on the
server and the client, instead of passing text through component
options.

Translations are plain ICU MessageFormat strings, so one JSON config
serves both sides of the server/client boundary. The formatter supports
only what the strings need: `{name}` arguments and one plural block per
string with the CLDR categories, selected through `Intl.PluralRules`
for the configured locale. No dependencies are added.

`DEFAULT_TRANSLATIONS` defines the keys and the English templates;
`DiffsTranslations` is derived from it. `i18n.set()` replaces every
translation and the locale, falls back to English for anything left
out, validates and compiles before changing state, and notifies
subscribers only on a real change. Nothing reads the store yet; the
renderer and component subscriptions follow.

* refactor(diffs): read diff text from the i18n store

Hunk separators and the no-newline marker now take their text from the
`i18n` singleton. The `labels` diff option, its `DiffLabels` type, the
`DEFAULT_DIFF_LABELS` defaults, the `resolveDiffLabels` helper, and the
hand-rolled English plural rule are removed; nothing is passed through
component options any more.

`createSeparator` and `createNoNewlineElement` call `i18n.t()`
themselves, so their signatures return to what they were before the
option existed. With the default English translations the rendered
output is unchanged.

* fix(i18n): add strings for UnresolvedFile

* feat(diffs): re-render mounted diffs when translations change

Switch languages with `i18n.set()` while a diff is on screen and its
hunk separators, no-newline marker, and merge-conflict buttons now
update in place, like a theme change does. Before, new translations
only showed up on the next render for an unrelated reason.

`FileDiff` subscribes to the i18n store where it subscribes to theme
changes, unsubscribes in `cleanUp`, and handles the change with a
plain `rerender()`: separators and injected rows are rebuilt from the
cached highlight on every forced render, so no cache is cleared.
`VirtualizedFileDiff` and `UnresolvedFile` inherit it. `CodeView` does
not subscribe; its mounted items do, and recycled shells hold no
rendered rows.

The merge-conflict action buttons ("Accept current change", "Accept
incoming change", "Accept both") move into `DEFAULT_TRANSLATIONS` and
are read through `i18n.t()` at render time.

* docs(diffs): document the i18n store

Add an Internationalization page: configuring `i18n.set()` once at boot
on server and client, switching languages at runtime from JSON files,
the supported ICU message subset with plural categories, the full key
table with English defaults, and the server-rendering rules. Register
the section with the llms.txt generator so the docs build includes it.

Remove the `labels` option from the React and Vanilla shared-options
examples, since that option no longer exists.

* feat(diffs): read editor search panel text from the i18n store

The search panel's placeholders, match status, option toggles, and
buttons were hard-coded English, so a translated app still showed an
English find-and-replace bar. They now come from `DEFAULT_TRANSLATIONS`
through `i18n.t()`, read when the panel is built, which happens on each
open.

The match count becomes a plural template, so a single match reads
"1 result" instead of "1 results". The docs key table lists the new
keys.

* test(diffs): clean up mounted instances and expect the singular count

CI ran `UnresolvedFile.sequentialResolve.test.ts` before `i18n.test.ts`
in one process. The first mounts an `UnresolvedFile` and never cleans
it up, so it stays subscribed to the i18n store, and the later
`i18n.set()` re-rendered it into a torn-down DOM. Three virtualized
hydration tests left rendered instances behind the same way. Each now
calls `cleanUp()` in its `finally`.

The search e2e test expected "1 results"; the panel now says
"1 result".

* test(diffs): drop i18n subscribers when a test DOM is torn down

CI ran test files in an order where a `VirtualizedFileDiff` left mounted
by `virtualizedEditorViewport.test.ts` was still subscribed to the i18n
store when a later file called `i18n.set()`. The re-render threw into a
DOM that no longer existed and failed every translation test. Bun lists
files in filesystem order, which is alphabetical on macOS and arbitrary
on Linux, so the order never occurred locally.

Patching each leaking test is not reliable, so the DOM harness now
drops every subscriber and restores the English defaults on install and
on cleanup, the same way it already clears the render queue. The fake
DOM harness in `hydration.test.ts` does the same. `i18n.clearSubscribers`
is marked `@internal` for that purpose. The leaking test also cleans up
its instance.

---------

Co-authored-by: Amadeus Demarzi <[email protected]>
amadeus added a commit that referenced this pull request Nov 22, 2026
* [diffs] Add a labels option for localizing diff text

* feat(diffs): add an i18n store for user-visible diff text

Apps that translate their UI cannot change the English text the diff
renders, such as "12 unmodified lines" or "Expand all". This adds a
package-level `i18n` singleton the app configures once at boot, on the
server and the client, instead of passing text through component
options.

Translations are plain ICU MessageFormat strings, so one JSON config
serves both sides of the server/client boundary. The formatter supports
only what the strings need: `{name}` arguments and one plural block per
string with the CLDR categories, selected through `Intl.PluralRules`
for the configured locale. No dependencies are added.

`DEFAULT_TRANSLATIONS` defines the keys and the English templates;
`DiffsTranslations` is derived from it. `i18n.set()` replaces every
translation and the locale, falls back to English for anything left
out, validates and compiles before changing state, and notifies
subscribers only on a real change. Nothing reads the store yet; the
renderer and component subscriptions follow.

* refactor(diffs): read diff text from the i18n store

Hunk separators and the no-newline marker now take their text from the
`i18n` singleton. The `labels` diff option, its `DiffLabels` type, the
`DEFAULT_DIFF_LABELS` defaults, the `resolveDiffLabels` helper, and the
hand-rolled English plural rule are removed; nothing is passed through
component options any more.

`createSeparator` and `createNoNewlineElement` call `i18n.t()`
themselves, so their signatures return to what they were before the
option existed. With the default English translations the rendered
output is unchanged.

* fix(i18n): add strings for UnresolvedFile

* feat(diffs): re-render mounted diffs when translations change

Switch languages with `i18n.set()` while a diff is on screen and its
hunk separators, no-newline marker, and merge-conflict buttons now
update in place, like a theme change does. Before, new translations
only showed up on the next render for an unrelated reason.

`FileDiff` subscribes to the i18n store where it subscribes to theme
changes, unsubscribes in `cleanUp`, and handles the change with a
plain `rerender()`: separators and injected rows are rebuilt from the
cached highlight on every forced render, so no cache is cleared.
`VirtualizedFileDiff` and `UnresolvedFile` inherit it. `CodeView` does
not subscribe; its mounted items do, and recycled shells hold no
rendered rows.

The merge-conflict action buttons ("Accept current change", "Accept
incoming change", "Accept both") move into `DEFAULT_TRANSLATIONS` and
are read through `i18n.t()` at render time.

* docs(diffs): document the i18n store

Add an Internationalization page: configuring `i18n.set()` once at boot
on server and client, switching languages at runtime from JSON files,
the supported ICU message subset with plural categories, the full key
table with English defaults, and the server-rendering rules. Register
the section with the llms.txt generator so the docs build includes it.

Remove the `labels` option from the React and Vanilla shared-options
examples, since that option no longer exists.

* feat(diffs): read editor search panel text from the i18n store

The search panel's placeholders, match status, option toggles, and
buttons were hard-coded English, so a translated app still showed an
English find-and-replace bar. They now come from `DEFAULT_TRANSLATIONS`
through `i18n.t()`, read when the panel is built, which happens on each
open.

The match count becomes a plural template, so a single match reads
"1 result" instead of "1 results". The docs key table lists the new
keys.

* test(diffs): clean up mounted instances and expect the singular count

CI ran `UnresolvedFile.sequentialResolve.test.ts` before `i18n.test.ts`
in one process. The first mounts an `UnresolvedFile` and never cleans
it up, so it stays subscribed to the i18n store, and the later
`i18n.set()` re-rendered it into a torn-down DOM. Three virtualized
hydration tests left rendered instances behind the same way. Each now
calls `cleanUp()` in its `finally`.

The search e2e test expected "1 results"; the panel now says
"1 result".

* test(diffs): drop i18n subscribers when a test DOM is torn down

CI ran test files in an order where a `VirtualizedFileDiff` left mounted
by `virtualizedEditorViewport.test.ts` was still subscribed to the i18n
store when a later file called `i18n.set()`. The re-render threw into a
DOM that no longer existed and failed every translation test. Bun lists
files in filesystem order, which is alphabetical on macOS and arbitrary
on Linux, so the order never occurred locally.

Patching each leaking test is not reliable, so the DOM harness now
drops every subscriber and restores the English defaults on install and
on cleanup, the same way it already clears the render queue. The fake
DOM harness in `hydration.test.ts` does the same. `i18n.clearSubscribers`
is marked `@internal` for that purpose. The leaking test also cleans up
its instance.

---------

Co-authored-by: Amadeus Demarzi <[email protected]>

This branch was successfully deployed

4 active deployments
Preview – pierre-docs-diffs — 33ba02e3 Deployed Nov 8, 2026 by vercel[bot]
Preview – pierre-docs-trees — 33ba02e3 Deployed Nov 8, 2026 by vercel[bot]
Preview – pierre-diffshub — 33ba02e3 Deployed Nov 8, 2026 by vercel[bot]
Preview – pierrejs-diff-demo — 33ba02e3 Deployed Nov 8, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants