mirror of
https://github.com/Open-Dev-Society/OpenStock.git
synced 2026-11-22 00:33:06 +08:00
Arabic as a third language on next-intl: messages/ar.json (469 keys), dir=rtl set before first paint, IBM Plex Sans Arabic only for Arabic, a right-side mobile drawer, logical CSS with LTR unchanged, Arabic TradingView widgets and welcome intro. English and Polish render exactly as before; the public site stays English and static. Co-Authored-By: ahmaddirar-ios <57848046+ahmaddirar-ios@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
52 lines
2.0 KiB
TypeScript
52 lines
2.0 KiB
TypeScript
'use client';
|
|
|
|
import { useTransition } from "react";
|
|
import { useRouter } from "next/navigation";
|
|
import { useLocale, useTranslations } from "next-intl";
|
|
import { Languages, Loader2 } from "lucide-react";
|
|
import {
|
|
DropdownMenu,
|
|
DropdownMenuContent,
|
|
DropdownMenuRadioGroup,
|
|
DropdownMenuRadioItem,
|
|
DropdownMenuTrigger,
|
|
} from "@/components/ui/dropdown-menu";
|
|
import { LOCALES, LOCALE_NAMES, isLocale } from "@/i18n/config";
|
|
import { setLocale } from "@/lib/actions/locale.actions";
|
|
import { cn } from "@/lib/utils";
|
|
|
|
// Language names stay in their own language so anyone can find theirs.
|
|
export default function LanguageSwitcher({ className }: { className?: string }) {
|
|
const t = useTranslations('Language');
|
|
const locale = useLocale();
|
|
const router = useRouter();
|
|
const [pending, startTransition] = useTransition();
|
|
|
|
const change = (next: string) => {
|
|
if (next === locale || !isLocale(next)) return;
|
|
startTransition(async () => {
|
|
await setLocale(next);
|
|
router.refresh();
|
|
});
|
|
};
|
|
|
|
return (
|
|
<DropdownMenu>
|
|
<DropdownMenuTrigger disabled={pending} className={cn('side-item h-8 w-full text-start outline-none', className)}>
|
|
{pending ? <Loader2 className="animate-spin" /> : <Languages />}
|
|
<span className="flex-1">{t('label')}</span>
|
|
<span className="text-xs text-faint" lang={locale}>{LOCALE_NAMES[locale]}</span>
|
|
</DropdownMenuTrigger>
|
|
<DropdownMenuContent side="top" align="start" className="w-(--radix-dropdown-menu-trigger-width)">
|
|
<DropdownMenuRadioGroup value={locale} onValueChange={change}>
|
|
{LOCALES.map((code) => (
|
|
<DropdownMenuRadioItem key={code} value={code} lang={code}>
|
|
{LOCALE_NAMES[code]}
|
|
</DropdownMenuRadioItem>
|
|
))}
|
|
</DropdownMenuRadioGroup>
|
|
</DropdownMenuContent>
|
|
</DropdownMenu>
|
|
);
|
|
}
|