diff --git a/components/global/Header/LanguageSelect/index.js b/components/global/Header/LanguageSelect/index.js index 2915c44b..5bc9ddaa 100644 --- a/components/global/Header/LanguageSelect/index.js +++ b/components/global/Header/LanguageSelect/index.js @@ -2,8 +2,9 @@ import PropTypes from "prop-types"; import { useEffect, useState } from "react"; import { useRouter, useSearchParams, usePathname } from "next/navigation"; import { useTranslation } from "react-i18next"; +import { getCookie } from "cookies-next"; +import { cookieName, fallbackLng } from "@/lib/i18n/settings"; import * as Styled from "./styles"; -import { fallbackLng } from "@/lib/i18n/settings"; const filterSearchParams = (searchParams) => { const filteredParams = []; @@ -24,8 +25,9 @@ export default function LanguageSelect({ id }) { const searchParams = useSearchParams(); const { t, - i18n: { changeLanguage, resolvedLanguage: locale }, + i18n: { changeLanguage }, } = useTranslation(); + const locale = getCookie(cookieName); const isDefaultLocale = fallbackLng.includes(locale); @@ -47,9 +49,9 @@ export default function LanguageSelect({ id }) { const route = `/${newLocale}/${parts.join("/")}${filterSearchParams( searchParams )}`; - changeLanguage(newLocale); setLoading(true); router.replace(route, { scroll: false }); + changeLanguage(newLocale); } }; diff --git a/package.json b/package.json index 3148b52b..3991b3cc 100644 --- a/package.json +++ b/package.json @@ -65,6 +65,7 @@ "add": "^2.0.6", "classnames": "^2.3.1", "convert": "^4.13.0", + "cookies-next": "^4.2.1", "feed": "^4.2.2", "focus-trap": "^7.0.0", "focus-visible": "^5.1.0", diff --git a/yarn.lock b/yarn.lock index e565c6c0..7ba836c9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3340,6 +3340,11 @@ dependencies: "@types/node" "*" +"@types/cookie@^0.6.0": + version "0.6.0" + resolved "https://registry.yarnpkg.com/@types/cookie/-/cookie-0.6.0.tgz#eac397f28bf1d6ae0ae081363eca2f425bedf0d5" + integrity sha512-4Kh9a6B2bQciAhf7FSuMRRkUWecJgJu9nPnx3yzpsfXX/c50REIqpHY4C82bXP90qrLtXtkDxTZosYO3UpOwlA== + "@types/detect-port@^1.3.0": version "1.3.2" resolved "https://registry.yarnpkg.com/@types/detect-port/-/detect-port-1.3.2.tgz#8c06a975e472803b931ee73740aeebd0a2eb27ae" @@ -4995,6 +5000,19 @@ cookie@0.5.0: resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.5.0.tgz#d1f5d71adec6558c58f389987c366aa47e994f8b" integrity sha512-YZ3GUyn/o8gfKJlnlX7g7xq4gyO6OSuhGPKaaGssGB2qgDUS0gPgtTvoyZLTt9Ab6dC4hfc9dV5arkvc/OCmrw== +cookie@^0.6.0: + version "0.6.0" + resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.6.0.tgz#2798b04b071b0ecbff0dbb62a505a8efa4e19051" + integrity sha512-U71cyTamuh1CRNCfpGY6to28lxvNwPG4Guz/EVjgf3Jmzv0vlDp1atT9eS5dDjMYHucpHbWns6Lwf3BKz6svdw== + +cookies-next@^4.2.1: + version "4.2.1" + resolved "https://registry.yarnpkg.com/cookies-next/-/cookies-next-4.2.1.tgz#a0c2942afee16f1ffc2bc05a003c7c0cf32deda5" + integrity sha512-qsjtZ8TLlxCSX2JphMQNhkm3V3zIMQ05WrLkBKBwu50npBbBfiZWIdmSMzBGcdGKfMK19E0PIitTfRFAdMGHXg== + dependencies: + "@types/cookie" "^0.6.0" + cookie "^0.6.0" + core-js-compat@^3.25.1: version "3.27.1" resolved "https://registry.yarnpkg.com/core-js-compat/-/core-js-compat-3.27.1.tgz#b5695eb25c602d72b1d30cbfba3cb7e5e4cf0a67"