From 561180cb4005acb82282575d7d7fbaaa55e5187b Mon Sep 17 00:00:00 2001 From: Nuzhy-Deriv Date: Wed, 30 Apr 2025 12:04:28 +0800 Subject: [PATCH] fix: set 'en' to language cookie if no locale in url --- src/js/footer/updateUrlAsPerLanguage/index.js | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/js/footer/updateUrlAsPerLanguage/index.js b/src/js/footer/updateUrlAsPerLanguage/index.js index ba0bbb2..5913640 100644 --- a/src/js/footer/updateUrlAsPerLanguage/index.js +++ b/src/js/footer/updateUrlAsPerLanguage/index.js @@ -27,31 +27,35 @@ const updateURLAsPerUserLanguage = () => { const current_query = window.location.search; const paths = current_path.split("/"); const first_path = paths[1]; + const has_language_in_url = languages.includes(first_path || ""); - const is_no_language = - paths.includes("careers") || - paths.includes("locations") || - paths.includes("derivtech") || - paths.includes("derivlife") || - paths.includes("trading-terms-glossary") || - paths.includes("product-explorer") || - paths.includes("eu-careers") || - paths.includes("our-locations") || - paths.includes("academy") || - paths.includes("trading-specifications"); - if (has_language_in_url) { - setLanguageCookie(first_path); - } + const is_no_language = [ + "careers", + "locations", + "derivtech", + "derivlife", + "trading-terms-glossary", + "product-explorer", + "eu-careers", + "our-locations", + "academy", + "trading-specifications", + ].some((path) => paths.includes(path)); + + setLanguageCookie(has_language_in_url ? first_path : "en"); + const user_language = getCookieByKey(document.cookie, "webflow-user-language")?.toLowerCase() || "en"; const language = has_language_in_url ? first_path : user_language; + if (!has_language_in_url && user_language === "en") return; if (first_path === user_language) return; if (has_language_in_url && first_path !== user_language) { setLanguageCookie(language); return; } + if (!is_no_language) { const updated_path = has_language_in_url ? paths.map((item) => (item === first_path ? language : item)).join("/")