ENJOY UP TO 1 MONTH FREE!* Schedule your personalized tour today!

/** * @name Auto-Translate to Spanish (MODIFIED for AlisterLakeLynn.com/Entrata) * @description This script checks the current URL for a "?lang=es" parameter. * If the parameter is found, it automatically attempts to find and click * the "Spanish" language link, typically found in the site's footer. */ (function() { 'use strict'; /** * Attempts to find and click the UI element to change the site language to Spanish. */ function switchLanguageToSpanish() { // The previous site used complex IDs and clicks. This site (Entrata) likely // uses a direct link, often in the footer, with the text 'Spanish' or 'Español'. // Find ALL anchor links on the page. const allLinks = document.querySelectorAll('a'); let spanishLink = null; // Iterate through all links to find the one with the correct language text. // This is more resilient than relying on unknown IDs/Classes. for (const link of allLinks) { const text = link.textContent.trim(); // Check for common Spanish language link texts (case-insensitive for safety) if (text.toLowerCase().includes('spanish') || text.toLowerCase().includes('español')) { spanishLink = link; break; // Found the link, stop searching } } if (spanishLink) { console.log('Auto-Translate: Spanish language option found. Clicking to translate...'); // Simulate a click on the "Spanish" link to trigger the translation. spanishLink.click(); } else { // Fallback for cases where the link text is not simple "Spanish" or "Español". // A direct link is often a single element in the footer. We'll search for // a common pattern: an anchor tag with lang="es" or an href ending in '?lang=es'. const fallbackLink = document.querySelector('a[lang="es"], a[href*="?lang=es"]'); if (fallbackLink) { console.log('Auto-Translate: Fallback Spanish link found. Clicking to translate...'); fallbackLink.click(); } else { console.error('Auto-Translate Error: The "Spanish" language link was not found using text or common attributes.'); } } } /** * Main execution block that runs when the script is loaded. */ try { const urlParams = new URLSearchParams(window.location.search); const targetLang = 'es'; // Check two conditions: // 1. The URL has the '?lang=es' parameter. // 2. The page's HTML tag does NOT already start with 'es' if (urlParams.get('lang') === targetLang && !document.documentElement.lang.startsWith(targetLang)) { console.log('Auto-Translate: "?lang=es" parameter detected. Attempting to switch language.'); // Wait for a short moment before clicking. Sometimes translation elements // are loaded via JS after the DOM is ready. 500ms is a safe delay. setTimeout(() => { switchLanguageToSpanish(); }, 500); } else { console.log('Auto-Translate: No action needed. Either the URL parameter is missing or the page is already in Spanish.'); } } catch (error) { console.error('An unexpected error occurred in the auto-translate script:', error); } })();