A full-featured download manager.
fix(i18n): localize shared dialog and sidebar controls (#2212)
Dr_rOot168315b1c633
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex 826dfdda..6ccf1da9 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -76,6 +76,7 @@ jobs:src/preload/preload.test.tssrc/renderer/lib/bootstrap-locale.test.tssrc/renderer/lib/i18n.test.ts+ src/renderer/components/ui/primitives-i18n.test.tsxsrc/renderer/components/language-sync.test.tsxsrc/renderer/components/locale-direction-provider.test.tsxsrc/renderer/components/onboarding/onboarding-language-select.test.tsxdiff --git a/src/renderer/components/ui/dialog.tsx b/src/renderer/components/ui/dialog.tsxindex f737db6c..9cc0fbb0 100644--- a/src/renderer/components/ui/dialog.tsx+++ b/src/renderer/components/ui/dialog.tsx@@ -3,6 +3,7 @@ import { CloseIcon } from '@renderer/components/icons'import { Button } from '@renderer/components/ui/button'import { cn } from '@renderer/lib/utils'import type * as React from 'react'+import { useTranslation } from 'react-i18next'function Dialog({ ...props }: DialogPrimitive.Root.Props) {return <DialogPrimitive.Root data-slot="dialog" {...props} />@@ -46,6 +47,7 @@ function DialogContent({overlayClassName?: stringshowCloseButton?: boolean}) {+ const { t } = useTranslation()return (<DialogPortal><DialogOverlay className={overlayClassName} />@@ -70,7 +72,7 @@ function DialogContent({}><CloseIcon />- <span className="sr-only">Close</span>+ <span className="sr-only">{t('common.close')}</span></DialogPrimitive.Close>)}</DialogPrimitive.Popup>@@ -96,6 +98,7 @@ function DialogFooter({}: React.ComponentProps<'div'> & {showCloseButton?: boolean}) {+ const { t } = useTranslation()return (<divdata-slot="dialog-footer"@@ -108,7 +111,7 @@ function DialogFooter({{children}{showCloseButton && (<DialogPrimitive.Close render={<Button variant="outline" />}>- Close+ {t('common.close')}</DialogPrimitive.Close>)}</div>diff --git a/src/renderer/components/ui/primitives-i18n.test.tsx b/src/renderer/components/ui/primitives-i18n.test.tsxnew file mode 100644index 00000000..53bca939--- /dev/null+++ b/src/renderer/components/ui/primitives-i18n.test.tsx@@ -0,0 +1,114 @@+import '@testing-library/jest-dom/vitest'+import { applyRendererLocale } from '@renderer/lib/i18n'+import { act, cleanup, fireEvent, render, screen } from '@testing-library/react'+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'+import { Dialog, DialogContent, DialogFooter, DialogTitle } from './dialog'+import { Sheet, SheetContent, SheetTitle } from './sheet'+import {+ Sidebar,+ SidebarProvider,+ SidebarRail,+ SidebarTrigger,+} from './sidebar'++beforeEach(async () => {+ await applyRendererLocale('en-US')+ vi.stubGlobal('localStorage', {+ getItem: vi.fn(() => null),+ setItem: vi.fn(),+ })+ vi.stubGlobal('innerWidth', 1024)+ vi.stubGlobal(+ 'matchMedia',+ vi.fn(() => ({+ matches: false,+ addEventListener: vi.fn(),+ removeEventListener: vi.fn(),+ }))+ )+})++afterEach(async () => {+ cleanup()+ vi.unstubAllGlobals()+ await applyRendererLocale('en-US')+})++describe('shared control localization', () => {+ it('updates both dialog close controls without reopening the dialog', async () => {+ const onOpenChange = vi.fn()+ render(+ <Dialog defaultOpen onOpenChange={onOpenChange}>+ <DialogContent>+ <DialogTitle>Example</DialogTitle>+ <DialogFooter showCloseButton />+ </DialogContent>+ </Dialog>+ )+ expect(screen.getAllByRole('button', { name: 'Close' })).toHaveLength(2)+ await act(() => applyRendererLocale('fr'))+ const buttons = screen.getAllByRole('button', { name: 'Fermer' })+ expect(buttons).toHaveLength(2)+ expect(screen.queryByRole('button', { name: 'Close' })).toBeNull()+ fireEvent.click(buttons[0])+ expect(onOpenChange).toHaveBeenCalledWith(false, expect.anything())+ })++ it('updates the sheet close control while it is open', async () => {+ const onOpenChange = vi.fn()+ render(+ <Sheet defaultOpen onOpenChange={onOpenChange}>+ <SheetContent>+ <SheetTitle>Example</SheetTitle>+ </SheetContent>+ </Sheet>+ )+ await act(() => applyRendererLocale('zh-TW'))+ fireEvent.click(screen.getByRole('button', { name: '關閉' }))+ expect(onOpenChange).toHaveBeenCalledWith(false, expect.anything())+ })++ it('localizes the sidebar trigger and rail without losing toggle behavior', async () => {+ const { container } = render(+ <SidebarProvider>+ <SidebarTrigger />+ <Sidebar>+ <SidebarRail />+ </Sidebar>+ </SidebarProvider>+ )+ await act(() => applyRendererLocale('fr'))+ const label = 'Afficher ou masquer la barre latérale'+ const controls = screen.getAllByRole('button', { name: label })+ expect(controls).toHaveLength(2)+ expect(screen.queryByText('Toggle Sidebar')).toBeNull()+ expect(screen.getByTitle(label)).toBeInTheDocument()+ fireEvent.click(controls[0])+ expect(+ container.querySelector('[data-slot="sidebar-wrapper"]')+ ).toHaveAttribute('data-state', 'collapsed')+ fireEvent.click(controls[1])+ expect(+ container.querySelector('[data-slot="sidebar-wrapper"]')+ ).toHaveAttribute('data-state', 'expanded')+ })++ it('gives the narrow-screen navigation sheet a localized name and description', async () => {+ vi.stubGlobal('innerWidth', 600)+ await applyRendererLocale('fr')+ render(+ <SidebarProvider>+ <SidebarTrigger />+ <Sidebar>Navigation</Sidebar>+ </SidebarProvider>+ )+ fireEvent.click(+ screen.getByRole('button', {+ name: 'Afficher ou masquer la barre latérale',+ })+ )+ expect(+ await screen.findByRole('dialog', { name: 'Barre latérale' })+ ).toHaveAccessibleDescription('Navigation dans l’application.')+ })+})diff --git a/src/renderer/components/ui/sheet.tsx b/src/renderer/components/ui/sheet.tsxindex 0f75fdb0..e1945639 100644--- a/src/renderer/components/ui/sheet.tsx+++ b/src/renderer/components/ui/sheet.tsx@@ -4,6 +4,7 @@ import { Dialog as SheetPrimitive } from '@base-ui/react/dialog'import { CloseIcon } from '@renderer/components/icons'import { cn } from '@renderer/lib/utils'import type * as React from 'react'+import { useTranslation } from 'react-i18next'function Sheet({ ...props }: React.ComponentProps<typeof SheetPrimitive.Root>) {return <SheetPrimitive.Root data-slot="sheet" {...props} />@@ -53,6 +54,7 @@ function SheetContent({side?: 'top' | 'right' | 'bottom' | 'left'showCloseButton?: boolean}) {+ const { t } = useTranslation()return (<SheetPortal><SheetOverlay />@@ -76,7 +78,7 @@ function SheetContent({{showCloseButton && (<SheetPrimitive.Close className="absolute top-4 right-4 rounded-xs opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:ring-2 focus:ring-ring focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none data-open:bg-secondary"><CloseIcon className="size-4" />- <span className="sr-only">Close</span>+ <span className="sr-only">{t('common.close')}</span></SheetPrimitive.Close>)}</SheetPrimitive.Popup>diff --git a/src/renderer/components/ui/sidebar.tsx b/src/renderer/components/ui/sidebar.tsxindex 3289a47c..fef48c9a 100644--- a/src/renderer/components/ui/sidebar.tsx+++ b/src/renderer/components/ui/sidebar.tsx@@ -21,6 +21,7 @@ import { useIsMobile } from '@renderer/hooks/use-mobile'import { cn } from '@renderer/lib/utils'import { cva, type VariantProps } from 'class-variance-authority'import * as React from 'react'+import { useTranslation } from 'react-i18next'const SIDEBAR_STATE_KEY = 'sidebar_state'const SIDEBAR_WIDTH = '12.5rem'@@ -181,6 +182,7 @@ function Sidebar({variant?: 'sidebar' | 'floating' | 'inset'collapsible?: 'offcanvas' | 'icon' | 'none'}) {+ const { t } = useTranslation()const { isMobile, state, openMobile, setOpenMobile } = useSidebar()if (collapsible === 'none') {@@ -214,8 +216,10 @@ function Sidebar({side={side}><SheetHeader className="sr-only">- <SheetTitle>Sidebar</SheetTitle>- <SheetDescription>Displays the mobile sidebar.</SheetDescription>+ <SheetTitle>{t('chrome.sidebarTitle')}</SheetTitle>+ <SheetDescription>+ {t('chrome.sidebarDescription')}+ </SheetDescription></SheetHeader><div className="flex h-full w-full flex-col">{children}</div></SheetContent>@@ -276,6 +280,7 @@ function SidebarTrigger({onClick,...props}: React.ComponentProps<typeof Button>) {+ const { t } = useTranslation()const { toggleSidebar } = useSidebar()return (@@ -295,22 +300,23 @@ function SidebarTrigger({{...props}><SidebarIcon className="transition-opacity" />- <span className="sr-only">Toggle Sidebar</span>+ <span className="sr-only">{t('chrome.toggleSidebar')}</span></Button>)}function SidebarRail({ className, ...props }: React.ComponentProps<'button'>) {+ const { t } = useTranslation()const { toggleSidebar } = useSidebar()return (<buttondata-sidebar="rail"data-slot="sidebar-rail"- aria-label="Toggle Sidebar"+ aria-label={t('chrome.toggleSidebar')}tabIndex={-1}onClick={toggleSidebar}- title="Toggle Sidebar"+ title={t('chrome.toggleSidebar')}className={cn('absolute inset-y-0 z-20 hidden w-4 -translate-x-1/2 transition-all ease-linear group-data-[side=left]:-right-4 group-data-[side=right]:left-0 after:absolute after:inset-y-0 after:left-1/2 after:w-[2px] hover:after:bg-sidebar-border sm:flex','in-data-[side=left]:cursor-w-resize in-data-[side=right]:cursor-e-resize',diff --git a/src/shared/locales/en-US.json b/src/shared/locales/en-US.jsonindex 3c6799b7..9f033303 100644--- a/src/shared/locales/en-US.json+++ b/src/shared/locales/en-US.json@@ -102,7 +102,9 @@"restore": "Restore","close": "Close","toggleSidebar": "Toggle sidebar",- "newTask": "New task"+ "newTask": "New task",+ "sidebarTitle": "Sidebar",+ "sidebarDescription": "Application navigation."},"tray": {"newTask": "New Task",diff --git a/src/shared/locales/fr.json b/src/shared/locales/fr.jsonindex 3996200b..ae03ab27 100644--- a/src/shared/locales/fr.json+++ b/src/shared/locales/fr.json@@ -43,6 +43,8 @@"minimize": "Réduire","newTask": "Nouvelle tâche","restore": "Restaurer",+ "sidebarDescription": "Navigation dans l’application.",+ "sidebarTitle": "Barre latérale","toggleSidebar": "Afficher ou masquer la barre latérale"},"common": {diff --git a/src/shared/locales/zh-CN.json b/src/shared/locales/zh-CN.jsonindex f928c921..24637b39 100644--- a/src/shared/locales/zh-CN.json+++ b/src/shared/locales/zh-CN.json@@ -101,7 +101,9 @@"restore": "还原","close": "关闭","toggleSidebar": "切换边栏",- "newTask": "新建任务"+ "newTask": "新建任务",+ "sidebarTitle": "侧边栏",+ "sidebarDescription": "应用导航。"},"tray": {"newTask": "新建任务",diff --git a/src/shared/locales/zh-TW.json b/src/shared/locales/zh-TW.jsonindex 2fbeffca..255314b8 100644--- a/src/shared/locales/zh-TW.json+++ b/src/shared/locales/zh-TW.json@@ -101,7 +101,9 @@"restore": "還原","close": "關閉","toggleSidebar": "切換側邊欄",- "newTask": "新增任務"+ "newTask": "新增任務",+ "sidebarTitle": "側邊欄",+ "sidebarDescription": "應用程式導覽。"},"tray": {"newTask": "新增任務",