mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-11-16 14:54:23 +08:00
feat(i18n): add Russian UI and harden localization
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
'use client';
|
||||
|
||||
import { useTranslations } from 'next-intl';
|
||||
import * as React from 'react';
|
||||
import { Slot } from '@radix-ui/react-slot';
|
||||
import { ChevronRight, MoreHorizontal } from 'lucide-react';
|
||||
@@ -5,7 +8,15 @@ import { ChevronRight, MoreHorizontal } from 'lucide-react';
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
function Breadcrumb({ ...props }: React.ComponentProps<'nav'>) {
|
||||
return <nav aria-label='breadcrumb' data-slot='breadcrumb' {...props} />;
|
||||
const uiText = useTranslations('runtime');
|
||||
|
||||
return (
|
||||
<nav
|
||||
aria-label={uiText('ui_breadcrumb')}
|
||||
data-slot='breadcrumb'
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function BreadcrumbList({ className, ...props }: React.ComponentProps<'ol'>) {
|
||||
@@ -84,6 +95,8 @@ function BreadcrumbEllipsis({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<'span'>) {
|
||||
const uiText = useTranslations('runtime');
|
||||
|
||||
return (
|
||||
<span
|
||||
data-slot='breadcrumb-ellipsis'
|
||||
@@ -93,7 +106,7 @@ function BreadcrumbEllipsis({
|
||||
{...props}
|
||||
>
|
||||
<MoreHorizontal className='size-4' />
|
||||
<span className='sr-only'>More</span>
|
||||
<span className='sr-only'>{uiText('ui_more')}</span>
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { NextIntlClientProvider } from 'next-intl';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { Calendar } from './calendar';
|
||||
|
||||
describe('Calendar accessibility translations', () => {
|
||||
it('localizes Russian navigation, dropdowns and selected/today labels', () => {
|
||||
const date = new Date(2026, 0, 15);
|
||||
render(
|
||||
<NextIntlClientProvider locale='ru' messages={{}}>
|
||||
<Calendar
|
||||
mode='single'
|
||||
defaultMonth={date}
|
||||
today={date}
|
||||
selected={date}
|
||||
captionLayout='dropdown'
|
||||
/>
|
||||
</NextIntlClientProvider>,
|
||||
);
|
||||
expect(
|
||||
screen.getByRole('button', { name: 'Перейти к предыдущему месяцу' }),
|
||||
).toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByRole('button', { name: 'Перейти к следующему месяцу' }),
|
||||
).toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByRole('combobox', { name: 'Выберите месяц' }),
|
||||
).toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByRole('combobox', { name: 'Выберите год' }),
|
||||
).toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByRole('button', { name: /Сегодня.*выбрано/ }),
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('localizes Chinese navigation too', () => {
|
||||
render(
|
||||
<NextIntlClientProvider locale='zh-CN' messages={{}}>
|
||||
<Calendar defaultMonth={new Date(2026, 0, 1)} />
|
||||
</NextIntlClientProvider>,
|
||||
);
|
||||
expect(
|
||||
screen.getByRole('button', { name: '前往上个月' }),
|
||||
).toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByRole('button', { name: '前往下个月' }),
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import * as React from 'react';
|
||||
import { useLocale } from 'next-intl';
|
||||
import { enUS, zhCN } from 'date-fns/locale';
|
||||
import { enUS, ru, zhCN } from 'react-day-picker/locale';
|
||||
import {
|
||||
ChevronDownIcon,
|
||||
ChevronLeftIcon,
|
||||
@@ -27,7 +27,9 @@ function Calendar({
|
||||
buttonVariant?: React.ComponentProps<typeof Button>['variant'];
|
||||
}) {
|
||||
const uiLocale = useLocale();
|
||||
const locale = localeOverride ?? (uiLocale === 'zh-CN' ? zhCN : enUS);
|
||||
const locale =
|
||||
localeOverride ??
|
||||
(uiLocale === 'zh-CN' ? zhCN : uiLocale === 'ru' ? ru : enUS);
|
||||
const defaultClassNames = getDefaultClassNames();
|
||||
|
||||
return (
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
'use client';
|
||||
|
||||
import { useTranslations } from 'next-intl';
|
||||
|
||||
import * as React from 'react';
|
||||
import useEmblaCarousel, {
|
||||
type UseEmblaCarouselType,
|
||||
@@ -177,6 +179,8 @@ function CarouselPrevious({
|
||||
size = 'icon',
|
||||
...props
|
||||
}: React.ComponentProps<typeof Button>) {
|
||||
const uiText = useTranslations('runtime');
|
||||
|
||||
const { orientation, scrollPrev, canScrollPrev } = useCarousel();
|
||||
|
||||
return (
|
||||
@@ -196,7 +200,7 @@ function CarouselPrevious({
|
||||
{...props}
|
||||
>
|
||||
<ArrowLeft />
|
||||
<span className='sr-only'>Previous slide</span>
|
||||
<span className='sr-only'>{uiText('ui_previousSlide')}</span>
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
@@ -207,6 +211,8 @@ function CarouselNext({
|
||||
size = 'icon',
|
||||
...props
|
||||
}: React.ComponentProps<typeof Button>) {
|
||||
const uiText = useTranslations('runtime');
|
||||
|
||||
const { orientation, scrollNext, canScrollNext } = useCarousel();
|
||||
|
||||
return (
|
||||
@@ -226,7 +232,7 @@ function CarouselNext({
|
||||
{...props}
|
||||
>
|
||||
<ArrowRight />
|
||||
<span className='sr-only'>Next slide</span>
|
||||
<span className='sr-only'>{uiText('ui_nextSlide')}</span>
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
'use client';
|
||||
|
||||
import * as React from 'react';
|
||||
import { useTranslations } from 'next-intl';
|
||||
import { Command as CommandPrimitive } from 'cmdk';
|
||||
import { SearchIcon } from 'lucide-react';
|
||||
import { motion } from 'motion/react';
|
||||
@@ -31,8 +32,8 @@ function Command({
|
||||
}
|
||||
|
||||
function CommandDialog({
|
||||
title = 'Command Palette',
|
||||
description = 'Search for a command to run...',
|
||||
title,
|
||||
description,
|
||||
children,
|
||||
className,
|
||||
showCloseButton = false,
|
||||
@@ -45,11 +46,14 @@ function CommandDialog({
|
||||
showCloseButton?: boolean;
|
||||
shouldFilter?: boolean;
|
||||
}) {
|
||||
const t = useTranslations('runtime');
|
||||
return (
|
||||
<Dialog {...props}>
|
||||
<DialogHeader className='sr-only'>
|
||||
<DialogTitle>{title}</DialogTitle>
|
||||
<DialogDescription>{description}</DialogDescription>
|
||||
<DialogTitle>{title ?? t('ui_commandPalette')}</DialogTitle>
|
||||
<DialogDescription>
|
||||
{description ?? t('ui_commandSearch')}
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<DialogContent
|
||||
className={cn('overflow-hidden p-0 shadow-2xl', className)}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
'use client';
|
||||
|
||||
import { useTranslations } from 'next-intl';
|
||||
|
||||
import * as React from 'react';
|
||||
import * as DialogPrimitive from '@radix-ui/react-dialog';
|
||||
import { XIcon } from 'lucide-react';
|
||||
@@ -54,6 +56,8 @@ function DialogContent({
|
||||
}: React.ComponentProps<typeof DialogPrimitive.Content> & {
|
||||
showCloseButton?: boolean;
|
||||
}) {
|
||||
const uiText = useTranslations('runtime');
|
||||
|
||||
// 统一小屏样式:全宽留白、适度圆角、滚动保护
|
||||
const mobileBase = 'w-full max-w-[calc(100%-1.5rem)]';
|
||||
const desktopBase = 'sm:max-w-lg md:max-w-xl';
|
||||
@@ -75,7 +79,7 @@ function DialogContent({
|
||||
className="ring-offset-background focus:ring-ring data-[state=open]:bg-accent data-[state=open]:text-muted-foreground absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4"
|
||||
>
|
||||
<XIcon />
|
||||
<span className='sr-only'>Close</span>
|
||||
<span className='sr-only'>{uiText('ui_closeLabel')}</span>
|
||||
</DialogPrimitive.Close>
|
||||
)}
|
||||
</DialogPrimitive.Content>
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
'use client';
|
||||
|
||||
import { useTranslations } from 'next-intl';
|
||||
|
||||
import { CropIcon, RotateCcwIcon } from 'lucide-react';
|
||||
import { Slot } from '@radix-ui/react-slot';
|
||||
import {
|
||||
@@ -235,6 +237,8 @@ export const ImageCropContent = ({
|
||||
style,
|
||||
className,
|
||||
}: ImageCropContentProps) => {
|
||||
const uiText = useTranslations('runtime');
|
||||
|
||||
const {
|
||||
imgSrc,
|
||||
crop,
|
||||
@@ -262,7 +266,7 @@ export const ImageCropContent = ({
|
||||
{imgSrc && (
|
||||
// eslint-disable-next-line @next/next/no-img-element
|
||||
<img
|
||||
alt='crop'
|
||||
alt={uiText('ui_imageCrop')}
|
||||
className='size-full'
|
||||
height={400}
|
||||
onLoad={onImageLoad}
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
'use client';
|
||||
|
||||
import { useTranslations } from 'next-intl';
|
||||
import * as React from 'react';
|
||||
import {
|
||||
ChevronLeftIcon,
|
||||
@@ -9,10 +12,12 @@ import { cn } from '@/lib/utils';
|
||||
import { buttonVariants, type Button } from '@/components/ui/button';
|
||||
|
||||
function Pagination({ className, ...props }: React.ComponentProps<'nav'>) {
|
||||
const uiText = useTranslations('runtime');
|
||||
|
||||
return (
|
||||
<nav
|
||||
role='navigation'
|
||||
aria-label='pagination'
|
||||
aria-label={uiText('ui_pagination')}
|
||||
data-slot='pagination'
|
||||
className={cn('mx-auto flex w-full justify-center', className)}
|
||||
{...props}
|
||||
@@ -69,15 +74,17 @@ function PaginationPrevious({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof PaginationLink>) {
|
||||
const uiText = useTranslations('runtime');
|
||||
|
||||
return (
|
||||
<PaginationLink
|
||||
aria-label='Go to previous page'
|
||||
aria-label={uiText('ui_previousPage')}
|
||||
size='default'
|
||||
className={cn('gap-1 px-2.5 sm:pl-2.5', className)}
|
||||
{...props}
|
||||
>
|
||||
<ChevronLeftIcon />
|
||||
<span className='hidden sm:block'>Previous</span>
|
||||
<span className='hidden sm:block'>{uiText('ui_previousLabel')}</span>
|
||||
</PaginationLink>
|
||||
);
|
||||
}
|
||||
@@ -86,14 +93,16 @@ function PaginationNext({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof PaginationLink>) {
|
||||
const uiText = useTranslations('runtime');
|
||||
|
||||
return (
|
||||
<PaginationLink
|
||||
aria-label='Go to next page'
|
||||
aria-label={uiText('ui_nextPage')}
|
||||
size='default'
|
||||
className={cn('gap-1 px-2.5 sm:pr-2.5', className)}
|
||||
{...props}
|
||||
>
|
||||
<span className='hidden sm:block'>Next</span>
|
||||
<span className='hidden sm:block'>{uiText('ui_nextLabel')}</span>
|
||||
<ChevronRightIcon />
|
||||
</PaginationLink>
|
||||
);
|
||||
@@ -103,6 +112,8 @@ function PaginationEllipsis({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<'span'>) {
|
||||
const uiText = useTranslations('runtime');
|
||||
|
||||
return (
|
||||
<span
|
||||
aria-hidden
|
||||
@@ -111,7 +122,7 @@ function PaginationEllipsis({
|
||||
{...props}
|
||||
>
|
||||
<MoreHorizontalIcon className='size-4' />
|
||||
<span className='sr-only'>More pages</span>
|
||||
<span className='sr-only'>{uiText('ui_morePages')}</span>
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
'use client';
|
||||
|
||||
import { useTranslations } from 'next-intl';
|
||||
|
||||
import * as React from 'react';
|
||||
import * as SheetPrimitive from '@radix-ui/react-dialog';
|
||||
import { XIcon } from 'lucide-react';
|
||||
@@ -52,6 +54,8 @@ function SheetContent({
|
||||
}: React.ComponentProps<typeof SheetPrimitive.Content> & {
|
||||
side?: 'top' | 'right' | 'bottom' | 'left';
|
||||
}) {
|
||||
const uiText = useTranslations('runtime');
|
||||
|
||||
return (
|
||||
<SheetPortal>
|
||||
<SheetOverlay />
|
||||
@@ -74,7 +78,7 @@ function SheetContent({
|
||||
{children}
|
||||
<SheetPrimitive.Close className='ring-offset-background focus:ring-ring data-[state=open]:bg-secondary absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none'>
|
||||
<XIcon className='size-4' />
|
||||
<span className='sr-only'>Close</span>
|
||||
<span className='sr-only'>{uiText('ui_closeLabel')}</span>
|
||||
</SheetPrimitive.Close>
|
||||
</SheetPrimitive.Content>
|
||||
</SheetPortal>
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
'use client';
|
||||
|
||||
import { useTranslations } from 'next-intl';
|
||||
|
||||
import * as React from 'react';
|
||||
import { Slot } from '@radix-ui/react-slot';
|
||||
import { cva, type VariantProps } from 'class-variance-authority';
|
||||
@@ -164,6 +166,8 @@ function Sidebar({
|
||||
variant?: 'sidebar' | 'floating' | 'inset';
|
||||
collapsible?: 'offcanvas' | 'icon' | 'none';
|
||||
}) {
|
||||
const uiText = useTranslations('runtime');
|
||||
|
||||
const { isMobile, state, openMobile, setOpenMobile } = useSidebar();
|
||||
|
||||
if (collapsible === 'none') {
|
||||
@@ -197,8 +201,10 @@ function Sidebar({
|
||||
side={side}
|
||||
>
|
||||
<SheetHeader className='sr-only'>
|
||||
<SheetTitle>Sidebar</SheetTitle>
|
||||
<SheetDescription>Displays the mobile sidebar.</SheetDescription>
|
||||
<SheetTitle>{uiText('ui_sidebarLabel')}</SheetTitle>
|
||||
<SheetDescription>
|
||||
{uiText('ui_mobileSidebarDescription')}
|
||||
</SheetDescription>
|
||||
</SheetHeader>
|
||||
<div className='flex h-full w-full flex-col'>{children}</div>
|
||||
</SheetContent>
|
||||
@@ -261,6 +267,8 @@ function SidebarTrigger({
|
||||
onClick,
|
||||
...props
|
||||
}: React.ComponentProps<typeof Button>) {
|
||||
const uiText = useTranslations('runtime');
|
||||
|
||||
const { toggleSidebar } = useSidebar();
|
||||
|
||||
return (
|
||||
@@ -277,22 +285,24 @@ function SidebarTrigger({
|
||||
{...props}
|
||||
>
|
||||
<PanelLeftIcon />
|
||||
<span className='sr-only'>Toggle Sidebar</span>
|
||||
<span className='sr-only'>{uiText('ui_toggleSidebar')}</span>
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
|
||||
function SidebarRail({ className, ...props }: React.ComponentProps<'button'>) {
|
||||
const uiText = useTranslations('runtime');
|
||||
|
||||
const { toggleSidebar } = useSidebar();
|
||||
|
||||
return (
|
||||
<button
|
||||
data-sidebar='rail'
|
||||
data-slot='sidebar-rail'
|
||||
aria-label='Toggle Sidebar'
|
||||
aria-label={uiText('ui_toggleSidebar')}
|
||||
tabIndex={-1}
|
||||
onClick={toggleSidebar}
|
||||
title='Toggle Sidebar'
|
||||
title={uiText('ui_toggleSidebar')}
|
||||
className={cn(
|
||||
'hover:after:bg-sidebar-border 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] sm:flex',
|
||||
'in-data-[side=left]:cursor-w-resize in-data-[side=right]:cursor-e-resize',
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
TriangleAlertIcon,
|
||||
} from 'lucide-react';
|
||||
import { useTheme } from 'next-themes';
|
||||
import { useTranslations } from 'next-intl';
|
||||
import { Toaster as Sonner, type ToasterProps, useSonner } from 'sonner';
|
||||
import { useBellRing } from '@/contexts/bell-ring-context';
|
||||
|
||||
@@ -34,6 +35,7 @@ function ToastObserver() {
|
||||
|
||||
const Toaster = ({ ...props }: ToasterProps) => {
|
||||
const { theme = 'system' } = useTheme();
|
||||
const t = useTranslations('runtime');
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -41,6 +43,8 @@ const Toaster = ({ ...props }: ToasterProps) => {
|
||||
<Sonner
|
||||
theme={theme as ToasterProps['theme']}
|
||||
className='toaster group'
|
||||
containerAriaLabel={t('ui_toastRegion')}
|
||||
toastOptions={{ closeButtonAriaLabel: t('ui_closeToast') }}
|
||||
icons={{
|
||||
success: <CircleCheckIcon className='size-4' />,
|
||||
info: <InfoIcon className='size-4' />,
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
'use client';
|
||||
|
||||
import { useTranslations } from 'next-intl';
|
||||
import { Loader2Icon } from 'lucide-react';
|
||||
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
function Spinner({ className, ...props }: React.ComponentProps<'svg'>) {
|
||||
const uiText = useTranslations('runtime');
|
||||
|
||||
return (
|
||||
<Loader2Icon
|
||||
role='status'
|
||||
aria-label='Loading'
|
||||
aria-label={uiText('ui_loadingLabel')}
|
||||
className={cn('size-4 animate-spin', className)}
|
||||
{...props}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user