* refactor: move from next-international to next-intl * refactor: restructure translation package, * chore: change i18n-allay framework to next-intl * fix: add missing bold html tag to translation * fix: format issue * fix: address deepsource issues * fix: remove international-types dependency * fix: lint and typecheck issues * fix: typecheck issue * fix: typecheck issue * fix: issue with translations
26 lines
666 B
TypeScript
26 lines
666 B
TypeScript
import { useTransition } from "react";
|
|
import { usePathname, useRouter } from "next/navigation";
|
|
|
|
import type { SupportedLanguage } from "../config";
|
|
import { useCurrentLocale } from "./use-current-locale";
|
|
|
|
export const useChangeLocale = () => {
|
|
const currentLocale = useCurrentLocale();
|
|
const router = useRouter();
|
|
const pathname = usePathname();
|
|
const [isPending, startTransition] = useTransition();
|
|
|
|
return {
|
|
changeLocale: (newLocale: SupportedLanguage) => {
|
|
if (newLocale === currentLocale) {
|
|
return;
|
|
}
|
|
|
|
startTransition(() => {
|
|
router.replace(`/${newLocale}/${pathname}`);
|
|
});
|
|
},
|
|
isPending,
|
|
};
|
|
};
|