Skip to content

fix(i18n): re-render memoized translated UI on language changes - #35358

Merged
OrcaWin merged 2 commits into
mainfrom
OrcaWin/i18n-leftovers-1
Oct 28, 2026
Merged

OrcaWin merged 2 commits into
mainfrom
OrcaWin/i18n-leftovers-1

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​89 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​89
Prod 61 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​327 $\color{#cf222e}{\Huge{\mathbf{−}}}$​68 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​259

ELI5

When you switch Orca's UI language, some menus, rows and dialogs kept showing the old language until something else made them redraw. This makes them redraw as soon as the language (or a language pack) changes.

What Changed

  • New useUiLanguageRevision() hook (src/renderer/src/i18n/use-ui-language-revision.ts): a useSyncExternalStore subscription to the existing translation-resource version, which now notifies listeners and also advances on i18next languageChanged (one line in i18n.ts), so it covers language switches and catalog or plugin language-pack reloads.
  • The 34 memo() components that call translate() without their own subscription now call the hook. memo blocks the parent re-render a language switch relies on, and react-i18next only re-renders components that subscribe themselves. This includes the composer model/effort and permission pickers from [Bug]: Preserve remaining source-language fixes after Russian locale extraction #34783 and the right sidebar activity bar.
  • useMemo results that hold translated text (21 sites, e.g. right sidebar activity items, floating terminal menu, settings panes, source control action model) now list the revision as a dependency. useSettingsNavigationMetadata keys on it instead of i18n.language, so a reloaded plugin pack also refreshes. The standalone activity worktree cache and the code block language list use the language + resource version (createLocalizedCatalog) instead of the language or bundle identity alone.
  • New check-memo-translate-subscription ratchet: a memoized component in a file that calls translate() must subscribe. Two grandfathered entries render no translated text.

Why

One mechanism instead of sprinkling useTranslation() calls: it covers plugin language-pack reloads (same language, new resources), works in plain hooks, and the ratchet keeps new memoized components from regressing.

Linked Issue

Refs #34783 (the picker cases), Refs #32207

Visual Proof

N/A: no visual change in a single language; the fix only affects re-rendering after a language switch, covered by the test below.

Testing

  • native-chat-pickers-language-switch.test.tsx: renders the memoized permission and session option pickers with fixed props, switches to French, and asserts both relabel (fails without the hook).
  • Ratchet unit test; pnpm tc:web; lint with --deny-warnings; affected tests via pnpm check:changed.

Picker fix credit: @gentslava (#33370).

…hanges

Memoized components and useMemo/module caches that call translate() kept the
previous language after a switch or a plugin language-pack reload, because
react-i18next only re-renders components that subscribe themselves.

Add useUiLanguageRevision() (language + catalog revision via
useSyncExternalStore), call it in the 34 memoized translating components, key
translated useMemo results and module caches on it, and add a ratchet so new
memoized translating components must subscribe.

Fixes the composer pickers reported in #34783.

Co-authored-by: Vyacheslav Scherbinin <14369958+gentslava@users.noreply.github.com>
@greptile-apps

greptile-apps Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[High impact] The PR appears safe to merge; the remaining test coverage concern is non-blocking.

Findings

  1. P2 Pack refreshes lack render coverage ▶

Summary

Makes translated menus, rows, and dialogs redraw when the language or a language pack changes.

  • Translated menus, rows, and dialogs redraw when the language changes.
  • Cached activity names and code language labels refresh when translations change.
  • A check flags memoized components that translate text without subscribing.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Language changes] --> C[Shared change counter]
  B[Language pack added or removed] --> C
  C --> D[useUiLanguageRevision]
  D --> E[Components redraw]
  D --> F[Saved translated labels refresh]
Loading

Reviews (2) · Last reviewed commit: "fix(i18n): drive the language revision f..." · Reviewed by Greptile

Comment on lines +50 to +53
await act(() => i18n.changeLanguage('fr'))

expect(screen.getByText('Demander l’approbation')).toBeTruthy()
expect(screen.getByRole('button', { name: /^Modèle Opus/ })).toBeTruthy()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Pack refreshes lack render coverage

This test only changes the language. It does not check whether mounted components redraw when a language pack changes without changing i18n.language. Existing catalog tests call getters directly, so they would still pass if the hook stopped subscribing to resource changes.

Add a mounted-component test that replaces and removes the active pack while keeping props and language fixed, then checks the displayed labels.

@coderabbitai

coderabbitai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Walkthrough

The change adds a UI-language revision hook that observes language and translation-resource updates. Renderer components use the hook to refresh translated content and memoized values. Worktree display-name caching and the code-block language catalog also respond to translation-resource changes. A new ratchet script scans memoized renderer components for missing language subscriptions, with a baseline and tests.

Priority: Normal

Merge Risk: Low · up to 295c3

The new check misses some memoized components, and some existing source-control labels can remain in the previous language. These are bounded follow-up risks.

Pre-merge checks: Passed 3 · Failed 1 · Inconclusive 1

Failed Failed checks: 1 warning · 1 inconclusive

Check name Status Explanation Resolution
Description check Warning The description explains the change, user impact, rationale, testing, and visual proof. However, the Linked Issue section does not contain an actual issue link and uses only Refs #34783 and `Refs #3… Add an actual linked issue in the Fixes # section, complete the required checklist, and document cross-platform, SSH, mobile, compatibility, security, and performance considerations. Confirm the required validation commands or state that …
Docstring Coverage Inconclusive Docstring coverage is 13.79% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 3 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: updating memoized translated UI when the language changes.
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.
Full details: Description check

Explanation

The description explains the change, user impact, rationale, testing, and visual proof. However, the Linked Issue section does not contain an actual issue link and uses only Refs #34783 and Refs #32207, which the template explicitly says is insufficient. The required checklist and notes sections are also missing.

Resolution

Add an actual linked issue in the Fixes # section, complete the required checklist, and document cross-platform, SSH, mobile, compatibility, security, and performance considerations. Confirm the required validation commands or state that CI will cover them.

Full details: Docstring Coverage

Explanation

Docstring coverage is 13.79% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 29 functions across 50 files. (12 skipped: 2 unsupported, 10 over the file limit.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

Minor · Refresh the accessible label on language changes. · branch-line-total-chip.tsx:142

src/renderer/src/components/right-sidebar/source-control/panel/branch-line-total-chip.tsx:142
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Refresh the accessible label on language changes.

When only the language or translation resources change, splitRows refreshes, but accessibleLabel retains its previous translation. The chip then announces an old-language label to screen-reader users. Add languageRevision to the accessibleLabel memo dependencies. (raw.githubusercontent.com)


Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 12435999-6bd9-4ec1-a1c0-9c3342f2f022
Commits

Reviewing files that changed from the base of the PR and between 251c023 and 295c36a.

Files selected for processing: 62
  • config/memo-translate-subscription-baseline.txt
  • config/scripts/check-memo-translate-subscription-ratchet.mjs
  • config/scripts/check-memo-translate-subscription-ratchet.test.mjs
  • package.json
  • src/renderer/src/components/activity/activity-standalone-worktree.ts
  • src/renderer/src/components/activity/activity-thread-row.tsx
  • src/renderer/src/components/automations/AutomationRunsDashboard.tsx
  • src/renderer/src/components/browser-pane/annotate/MarkupToolbar.tsx
  • src/renderer/src/components/cmd-j/PaletteFilterMenu.tsx
  • src/renderer/src/components/editor/DiffNotesSendMenu.tsx
  • src/renderer/src/components/editor/VirtualMarkdownPreviewBody.tsx
  • src/renderer/src/components/editor/rich-markdown-code-block-languages.ts
  • src/renderer/src/components/editor/use-markdown-preview-foundation.ts
  • src/renderer/src/components/editor/useRichMarkdownReviewData.ts
  • src/renderer/src/components/floating-terminal/FloatingTerminalIconContextMenu.tsx
  • src/renderer/src/components/github-item-dialog/edit-item-fields/gh-edit-section.tsx
  • src/renderer/src/components/jira-user-picker.tsx
  • src/renderer/src/components/native-chat/NativeChatAutocompleteMenus.tsx
  • src/renderer/src/components/native-chat/NativeChatMessageRail.tsx
  • src/renderer/src/components/native-chat/NativeChatPermissionModePicker.tsx
  • src/renderer/src/components/native-chat/NativeChatQueuedMessageRows.tsx
  • src/renderer/src/components/native-chat/NativeChatSessionOptionPickers.tsx
  • src/renderer/src/components/native-chat/native-chat-pickers-language-switch.test.tsx
  • src/renderer/src/components/native-chat/use-native-chat-launch-prompt-delivery-notice.ts
  • src/renderer/src/components/native-chat/use-native-chat-pending-delivery.ts
  • src/renderer/src/components/right-sidebar/FileExplorer.tsx
  • src/renderer/src/components/right-sidebar/HostedReviewActions.tsx
  • src/renderer/src/components/right-sidebar/index.tsx
  • src/renderer/src/components/right-sidebar/source-control/ai/text-generation-dialog.tsx
  • src/renderer/src/components/right-sidebar/source-control/commit/recovery-notice.tsx
  • src/renderer/src/components/right-sidebar/source-control/listing/uncommitted-entry-row.tsx
  • src/renderer/src/components/right-sidebar/source-control/panel/branch-line-total-chip.tsx
  • src/renderer/src/components/right-sidebar/source-control/review/use-action-model.ts
  • src/renderer/src/components/right-sidebar/use-right-sidebar-activity-items.ts
  • src/renderer/src/components/settings/BrowserPane.tsx
  • src/renderer/src/components/settings/MobileEmulatorSettingsPane.tsx
  • src/renderer/src/components/settings/VoiceMicrophoneSetting.tsx
  • src/renderer/src/components/sidebar/AddProjectFromFolderDialog.tsx
  • src/renderer/src/components/sidebar/DeleteWorktreeDialog.tsx
  • src/renderer/src/components/sidebar/NonGitFolderDialog.tsx
  • src/renderer/src/components/sidebar/OrcaYamlTrustDialog.tsx
  • src/renderer/src/components/sidebar/RemoveFolderDialog.tsx
  • src/renderer/src/components/sidebar/SetupScriptPromptCard.tsx
  • src/renderer/src/components/sidebar/SidebarFilter.tsx
  • src/renderer/src/components/sidebar/SidebarRepositoryFilterSection.tsx
  • src/renderer/src/components/sidebar/SidebarWorkspaceOptionsMenu.tsx
  • src/renderer/src/components/sidebar/SleepTwinWorkspaceDialog.tsx
  • src/renderer/src/components/sidebar/WorkspaceKanbanCard.tsx
  • src/renderer/src/components/sidebar/WorkspaceKanbanStatusLane.tsx
  • src/renderer/src/components/sidebar/WorktreeCardAgents.tsx
  • src/renderer/src/components/sidebar/WorktreeMetaDialogDraft.tsx
  • src/renderer/src/components/sidebar/WorktreeParentPickerRow.tsx
  • src/renderer/src/components/sidebar/worktree-list/viewport/VirtualizedWorktreeViewport.tsx
  • src/renderer/src/components/status-bar/PetStatusSegment.tsx
  • src/renderer/src/components/status-bar/ResourcePtyRow.tsx
  • src/renderer/src/components/status-bar/use-owner-usage-rate-limits.ts
  • src/renderer/src/components/tab-bar/QuickLaunchButton.tsx
  • src/renderer/src/components/use-worktree-jump-palette-list-entries.ts
  • src/renderer/src/components/workspace-cleanup/workspace-cleanup-candidate-row.tsx
  • src/renderer/src/hooks/useSettingsNavigationMetadata.ts
  • src/renderer/src/i18n/translation-resource-version.ts
  • src/renderer/src/i18n/use-ui-language-revision.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.

const COMMENT = /\/\*[\s\S]*?\*\/|(?<![:'"`\\])\/\/.*$/gm
const TRANSLATE_CALL = /\btranslate\(/
const SUBSCRIPTION_CALL = /\b(?:useUiLanguageRevision|useTranslation)\(/
const MEMO_CALL = /\b(?:React\.)?memo\(\s*(?:function\s+([\w$]+)|([\w$]+)\s*[,)])/g

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Minor · Functional Correctness · Quick win

Detect arrow and anonymous memo components.

If a component uses const Row = memo(() => <span>{translate('k', 'Row')}</span>), MEMO_CALL finds no match. The ratchet then passes even though Row does not subscribe and can retain its old label after a language change. Recognize these memo arguments, derive the component name from the binding, and add regression cases. (raw.githubusercontent.com)

remoteStatus,
unresolvedConflictCount
unresolvedConflictCount,
languageRevision

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Minor · Functional Correctness · Quick win

Invalidate every translated action memo.

When the language changes without a source-control input change, only createPrHeaderAction recomputes. resolveCommitAreaPrimaryAction and resolveDropdownItems also produce translated labels and titles, but their memos retain the old text. Add languageRevision to both the primaryAction and dropdownItems dependency arrays. (raw.githubusercontent.com)

Tests that mock @/i18n/i18n have no i18n instance, so subscribe through
translation-resource-version (now also bumped on languageChanged) and give
useSyncExternalStore a server snapshot for renderToString tests.
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.

1 participant