diff --git a/src/components/footer.tsx b/src/components/footer.tsx index 1bc9202..3f1686a 100644 --- a/src/components/footer.tsx +++ b/src/components/footer.tsx @@ -5,6 +5,7 @@ import TextReveal from "./ui/text-reveal"; import { DiscordLogoIcon, GitHubLogoIcon } from "@radix-ui/react-icons"; import { MastodonLogo } from "./icons/mastodon"; import { Button } from "./ui/button"; +import LocaleSwitcher from "./locale-switcher"; export default function Footer() { return ( @@ -26,6 +27,8 @@ export default function Footer() { +

Change Language

+
diff --git a/src/components/locale-switcher.tsx b/src/components/locale-switcher.tsx new file mode 100644 index 0000000..9c5bf4e --- /dev/null +++ b/src/components/locale-switcher.tsx @@ -0,0 +1,31 @@ +"use client"; +import { usePathname, useRouter } from '@/i18n/routing'; +import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from './ui/select'; +import { SUPPORTED_LANGUAGES } from '@/i18n'; + +export default function LocaleSwitcher() { + const router = useRouter(); + const pathname = usePathname(); + const onLocaleChange = (value: string) => { + router.push(pathname, { locale: value }); + } + + return ( +
+ +
+ ) +} \ No newline at end of file diff --git a/src/i18n.ts b/src/i18n.ts index 0f5d10a..460b8fc 100644 --- a/src/i18n.ts +++ b/src/i18n.ts @@ -1,7 +1,6 @@ import { getRequestConfig } from "next-intl/server"; -import { headers } from "next/headers"; -export const SUPPORTED_LANGUAGES = ['en', 'de', 'ro']; +export const SUPPORTED_LANGUAGES = ['en', 'de']; export default getRequestConfig(async ({locale}) => { const lang = SUPPORTED_LANGUAGES.includes(locale) ? locale : 'en'; diff --git a/src/i18n/routing.ts b/src/i18n/routing.ts new file mode 100644 index 0000000..7c12c69 --- /dev/null +++ b/src/i18n/routing.ts @@ -0,0 +1,16 @@ +import {defineRouting} from 'next-intl/routing'; +import {createSharedPathnamesNavigation} from 'next-intl/navigation'; +import { SUPPORTED_LANGUAGES } from '@/i18n'; + +export const routing = defineRouting({ + // A list of all locales that are supported + locales: SUPPORTED_LANGUAGES, + + // Used when no locale matches + defaultLocale: 'en' +}); + +// Lightweight wrappers around Next.js' navigation APIs +// that will consider the routing configuration +export const {Link, redirect, usePathname, useRouter} = + createSharedPathnamesNavigation(routing); \ No newline at end of file