zooo-code commented on code in PR #429:
URL: https://github.com/apache/seatunnel-website/pull/429#discussion_r2786868571


##########
src/theme/NavbarItem/LocaleDropdownNavbarItem/index.js:
##########
@@ -34,84 +34,150 @@ export default function LocaleDropdownNavbarItem({
     const alternatePageUtils = useAlternatePageUtils();
     const { search, hash } = useLocation();
 
-    // Clear Google Translate cookie if we are on a native locale page
-    React.useEffect(() => {
-        if (currentLocale === 'en' || currentLocale === 'zh-CN') {
-            const clearCookie = (name) => {
-                document.cookie = name + '=; expires=Thu, 01 Jan 1970 00:00:00 
UTC; path=/;';
-                document.cookie = name + '=; expires=Thu, 01 Jan 1970 00:00:00 
UTC; path=/seatunnel-website;';
-                document.cookie = name + '=; expires=Thu, 01 Jan 1970 00:00:00 
UTC; domain=.' + document.domain + '; path=/;';
-            };
-            clearCookie('googtrans');
-            const frame = document.querySelector('.goog-te-banner-frame');
-            if (frame) {
-                frame.style.display = 'none';
+    // Helper function to get current Google Translate language code from 
cookie
+    const getGoogleTranslateLangCode = () => {
+        if (typeof document === 'undefined') return null;
+        const cookie = document.cookie.split('; ').find(row => 
row.startsWith('googtrans='));
+        if (cookie) {
+            const match = cookie.match(/googtrans=\/[^\/]+\/([^;]+)/);
+            return match ? match[1] : null;
+        }
+        return null;
+    };
+
+    // Helper function to get language label from cookie
+    const getLanguageLabelFromCookie = () => {
+        const langCode = getGoogleTranslateLangCode();
+        if (langCode) {
+            const googleLang = GOOGLE_LANGUAGES.find(lang => lang.code === 
langCode);
+            if (googleLang) {
+                return googleLang.label;
             }
         }
-    }, [currentLocale]);
+        return localeConfigs[currentLocale]?.label || 'English';
+    };
+
+    // State to track current language label
+    const [currentLangLabel, setCurrentLangLabel] = 
React.useState(getLanguageLabelFromCookie());
+
+    // Update language label based on Google Translate cookie
+    React.useEffect(() => {
+        const updateLabel = () => {
+            setCurrentLangLabel(getLanguageLabelFromCookie());
+        };
+
+        // Initial update
+        updateLabel();
+
+        // Listen for storage events (from other tabs/windows)
+        window.addEventListener('storage', updateLabel);
+
+        // Poll for cookie changes (fallback)
+        const interval = setInterval(updateLabel, 1000);
+

Review Comment:
   @davidzollo Thanks for the feedback!
   
   Removed setInterval and now updating the label immediately in onClick 
handlers. The storage listener is kept for cross-tab sync.
   
   Thanks!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to