-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bdbd0c8
commit 88f84c5
Showing
2 changed files
with
16 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,26 @@ | ||
'use client'; | ||
import { useLocale } from 'next-intl'; | ||
import { useRouter } from 'next/navigation'; | ||
import { ChangeEvent, useTransition } from 'react'; | ||
"use client"; | ||
import { useLocale } from "next-intl"; | ||
import { usePathname, useRouter } from "next/navigation"; | ||
import { ChangeEvent, useTransition } from "react"; | ||
|
||
export default function LocalSwitcher() { | ||
const [isPending, startTransition] = useTransition(); | ||
const router = useRouter(); | ||
const path = usePathname(); | ||
const localActive = useLocale(); | ||
|
||
const onSelectChange = (e: ChangeEvent<HTMLSelectElement>) => { | ||
const nextLocale = e.target.value; | ||
const onClick = () => { | ||
startTransition(() => { | ||
router.replace(`/${nextLocale}`); | ||
router.push(localActive === "en" ? "kn" : "en"); | ||
router.refresh(); | ||
}); | ||
}; | ||
return ( | ||
<label className='border-2 rounded m-2'> | ||
<p className='sr-only'>change language</p> | ||
<select | ||
defaultValue={localActive} | ||
className='bg-transparent py-2' | ||
onChange={onSelectChange} | ||
disabled={isPending} | ||
> | ||
<option value='en'>English</option> | ||
<option value='kn'>Kannada</option> | ||
</select> | ||
</label> | ||
<button | ||
className="subheading font-medium text-gray-900 hover:text-secondary-800 hover:scale-105 transition-all duration-150 ease-linear align-middle p-2" | ||
onClick={onClick} | ||
> | ||
{localActive === "en" ? "ಕ" : "en"} | ||
</button> | ||
); | ||
} | ||
} |