mirror of
https://github.com/yyhuni/xingrin.git
synced 2026-01-31 11:46:16 +08:00
- Replace all Chinese inline comments with English equivalents across 24 frontend component files - Update JSDoc comments to use English for better code documentation - Improve code readability and maintainability for international development team - Standardize comment style across directories, endpoints, ip-addresses, subdomains, and websites components - Ensure consistency with previous frontend refactoring efforts
54 lines
1.6 KiB
TypeScript
54 lines
1.6 KiB
TypeScript
'use client'
|
|
|
|
import { useLocale, useTranslations } from 'next-intl'
|
|
import { usePathname, useRouter } from '@/i18n/navigation'
|
|
import { locales, localeNames, type Locale } from '@/i18n/config'
|
|
import {
|
|
DropdownMenu,
|
|
DropdownMenuContent,
|
|
DropdownMenuItem,
|
|
DropdownMenuTrigger,
|
|
} from '@/components/ui/dropdown-menu'
|
|
import { Button } from '@/components/ui/button'
|
|
import { IconLanguage, IconCheck } from '@tabler/icons-react'
|
|
|
|
/**
|
|
* Language switcher component
|
|
* Displays current language, click to switch to other supported languages
|
|
*/
|
|
export function LanguageSwitcher() {
|
|
const locale = useLocale() as Locale
|
|
const router = useRouter()
|
|
const pathname = usePathname()
|
|
const tCommon = useTranslations("common")
|
|
|
|
const handleLocaleChange = (newLocale: Locale) => {
|
|
if (newLocale !== locale) {
|
|
router.replace(pathname, { locale: newLocale })
|
|
}
|
|
}
|
|
|
|
return (
|
|
<DropdownMenu>
|
|
<DropdownMenuTrigger asChild>
|
|
<Button variant="ghost" size="icon" className="h-8 w-8">
|
|
<IconLanguage className="h-4 w-4" />
|
|
<span className="sr-only">{tCommon("theme.switchLanguage")}</span>
|
|
</Button>
|
|
</DropdownMenuTrigger>
|
|
<DropdownMenuContent align="end">
|
|
{locales.map((l) => (
|
|
<DropdownMenuItem
|
|
key={l}
|
|
onClick={() => handleLocaleChange(l)}
|
|
className="flex items-center justify-between"
|
|
>
|
|
<span>{localeNames[l]}</span>
|
|
{locale === l && <IconCheck className="h-4 w-4 ml-2" />}
|
|
</DropdownMenuItem>
|
|
))}
|
|
</DropdownMenuContent>
|
|
</DropdownMenu>
|
|
)
|
|
}
|