From 01a6b27f41c39c1f5f8375ce974171d5ceda6608 Mon Sep 17 00:00:00 2001 From: moiz-deriv Date: Fri, 18 Oct 2024 09:45:53 +0800 Subject: [PATCH] refactor: added code for displaying current lanuage in header --- src/js/footer/displayCurrentLang/index.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/js/footer/displayCurrentLang/index.js diff --git a/src/js/footer/displayCurrentLang/index.js b/src/js/footer/displayCurrentLang/index.js new file mode 100644 index 0000000..4dc8ea0 --- /dev/null +++ b/src/js/footer/displayCurrentLang/index.js @@ -0,0 +1,16 @@ +document.addEventListener("DOMContentLoaded", function () { + let currentLocaleElement = document.querySelector( + ".locale > .new-navbar_dropdown-link.w--current" + ); + if (currentLocaleElement) { + let currentLocaleIsoCode = currentLocaleElement.getAttribute("hreflang"); + let currentLocaleIsoCodeTexts = document.querySelectorAll( + ".current-locale-iso-code" + ); + if (currentLocaleIsoCode && currentLocaleIsoCodeTexts.length) { + for (let currentLocaleIsoCodeText of currentLocaleIsoCodeTexts) { + currentLocaleIsoCodeText.innerText = currentLocaleIsoCode; + } + } + } +});