diff --git a/packages/ui/src/components/Molecules/LanguageSwitcher.tsx b/packages/ui/src/components/Molecules/LanguageSwitcher.tsx index c77683543..f10437d8d 100644 --- a/packages/ui/src/components/Molecules/LanguageSwitcher.tsx +++ b/packages/ui/src/components/Molecules/LanguageSwitcher.tsx @@ -1,5 +1,5 @@ import { Link, Locale, useLocation } from '@custom/schema'; -import { Menu, Transition } from '@headlessui/react'; +import { Menu, MenuButton, MenuItems, Transition } from '@headlessui/react'; import { ChevronDownIcon } from '@heroicons/react/20/solid'; import clsx from 'clsx'; import React, { Fragment } from 'react'; @@ -17,24 +17,29 @@ export function LanguageSwitcher() { const translations = useTranslations(); const [location] = useLocation(); + const currentLocale = Object.entries(translations).find( + ([, path]) => path === location.pathname, + )?.[0]; + const isMultiLingual = Object.keys(translations).length > 1; + return (
- {Object.values(Locale).map((locale) => ( - - {translations[locale] && - location.pathname !== translations[locale] ? null : ( - - {getLanguageName(locale)} - + + - ))} + disabled={!isMultiLingual} + > + {currentLocale} + +
- +
{Object.values(Locale).map((locale) => ( @@ -82,7 +87,7 @@ export function LanguageSwitcher() { ))}
-
+