mirror of
https://github.com/kyantech/Palmr.git
synced 2025-11-01 20:43:39 +00:00
This commit introduces the initial project setup including configuration files, API models, and necessary assets. The changes include: - Added Prettier and PostCSS configuration files - Included favicon and public assets like SVGs - Set up Next.js and theme provider configurations - Added TypeScript models for API endpoints and responses
83 lines
2.2 KiB
TypeScript
83 lines
2.2 KiB
TypeScript
import { useRouter } from "next/navigation";
|
|
import { IconLanguage } from "@tabler/icons-react";
|
|
import { useLocale } from "next-intl";
|
|
import { setCookie } from "nookies";
|
|
import ReactCountryFlag from "react-country-flag";
|
|
|
|
import { Button } from "@/components/ui/button";
|
|
import {
|
|
DropdownMenu,
|
|
DropdownMenuContent,
|
|
DropdownMenuItem,
|
|
DropdownMenuTrigger,
|
|
} from "@/components/ui/dropdown-menu";
|
|
|
|
const languages = {
|
|
"en-US": "English",
|
|
"pt-BR": "Português",
|
|
"fr-FR": "Français",
|
|
"es-ES": "Español",
|
|
"de-DE": "Deutsch",
|
|
"tr-TR": "Türkçe (Turkish)",
|
|
"ru-RU": "Русский (Russian)",
|
|
"hi-IN": "हिन्दी (Hindi)",
|
|
"ar-SA": "العربية (Arabic)",
|
|
"zh-CN": "中文 (Chinese)",
|
|
"ja-JP": "日本語 (Japanese)",
|
|
"ko-KR": "한국어 (Korean)",
|
|
};
|
|
|
|
const COOKIE_LANG_KEY = "NEXT_LOCALE";
|
|
const COOKIE_MAX_AGE = 365 * 24 * 60 * 60;
|
|
|
|
export function LanguageSwitcher() {
|
|
const locale = useLocale();
|
|
const router = useRouter();
|
|
|
|
const changeLanguage = (fullLocale: string) => {
|
|
setCookie(null, COOKIE_LANG_KEY, fullLocale, {
|
|
maxAge: COOKIE_MAX_AGE,
|
|
path: "/",
|
|
sameSite: "lax",
|
|
secure: process.env.NODE_ENV === "production",
|
|
});
|
|
|
|
router.refresh();
|
|
};
|
|
|
|
return (
|
|
<DropdownMenu>
|
|
<DropdownMenuTrigger asChild>
|
|
<Button variant="ghost" size="icon" className="h-9 w-9 p-0">
|
|
<IconLanguage className="h-5 w-5" />
|
|
<span className="sr-only">Change language</span>
|
|
</Button>
|
|
</DropdownMenuTrigger>
|
|
<DropdownMenuContent align="end">
|
|
{Object.entries(languages).map(([code, name]) => {
|
|
const isCurrentLocale = locale === code.split("-")[0];
|
|
|
|
return (
|
|
<DropdownMenuItem
|
|
key={code}
|
|
onClick={() => changeLanguage(code)}
|
|
className={isCurrentLocale ? "bg-accent" : ""}
|
|
>
|
|
<ReactCountryFlag
|
|
svg
|
|
countryCode={code.split("-")[1]}
|
|
style={{
|
|
marginRight: "8px",
|
|
width: "1em",
|
|
height: "1em",
|
|
}}
|
|
/>
|
|
{name}
|
|
</DropdownMenuItem>
|
|
);
|
|
})}
|
|
</DropdownMenuContent>
|
|
</DropdownMenu>
|
|
);
|
|
}
|