1 2 3 4/* ---------- ------------------------------ 5 6EARTHEN LANGUAGE SELECTOR v2.0 7 8-------------------------------------------*/ 9 10function switchLanguage(langCode) { 11 window.currentLanguage = langCode; 12 13 let currentTranslations = {}; 14 switch (langCode) { 15 case 'en': 16 currentTranslations = { ...en_Translations, ...en_Page_Translations, ...en_buwana_terms }; 17 break; 18 case 'fr': 19 currentTranslations = { ...fr_Translations, ...fr_Page_Translations, ...fr_buwana_terms }; 20 break; 21 case 'es': 22 currentTranslations = { ...es_Translations, ...es_Page_Translations, ...es_buwana_terms }; 23 break; 24 case 'id': 25 currentTranslations = { ...id_Translations, ...id_Page_Translations, ...id_buwana_terms }; 26 break; 27 case 'ar': 28 currentTranslations = { ...ar_Translations, ...ar_Page_Translations, ...ar_buwana_terms }; 29 break; 30 case 'zh': 31 currentTranslations = { ...zh_Translations, ...zh_Page_Translations, ...zh_buwana_terms }; 32 break; 33 case 'de': 34 currentTranslations = { ...de_Translations, ...de_Page_Translations, ...de_buwana_terms }; 35 break; 36 default: 37 console.warn(`No translations found for language: ${langCode}`); 38 return; 39 } 40 41 window.translations = currentTranslations; // â Make globally accessible 42 43 44 45 // RTL Support 46 const rtlLanguages = ['ar', 'he', 'fa', 'ur']; 47 const formContainer = document.getElementById('form-submission-box'); 48 if (formContainer) { 49 formContainer.setAttribute('dir', rtlLanguages.includes(langCode) ? 'rtl' : 'ltr'); 50 } 51 52 53 const elements = document.querySelectorAll('[data-lang-id]'); 54 elements.forEach(element => { 55 const langId = element.getAttribute('data-lang-id'); 56 const translation = currentTranslations[langId]; 57 if (translation) { 58 if (element.tagName.toLowerCase() === 'input' && element.type !== 'submit') { 59 element.placeholder = translation; 60 } else if (element.hasAttribute('aria-label')) { 61 element.setAttribute('aria-label', translation); 62 } else if (element.tagName.toLowerCase() === 'img') { 63 element.alt = translation; 64 } else { 65 element.innerHTML = translation; 66 } 67 } 68 }); 69} 70 71 72function loadTranslationScripts(lang, page, callback) { 73 const totalScripts = 3; 74 let loadedScripts = 0; 75 76 function scriptLoaded() { 77 loadedScripts++; 78 if (loadedScripts === totalScripts) { 79 callback(); // All scripts loaded 80 } 81 } 82 83 // Core UI translations 84 const coreScript = document.createElement('script'); 85 coreScript.src = `../translations/core-texts-${lang}.js?v=${version}`; 86 coreScript.onload = scriptLoaded; 87 document.head.appendChild(coreScript); 88 89 // Page-specific translations 90 const pageScript = document.createElement('script'); 91 pageScript.src = `../translations/${page}-${lang}.js?v=${version}`; 92 pageScript.onload = scriptLoaded; 93 document.head.appendChild(pageScript); 94 95 // Buwana-specific terms and policies 96 const buwanaScript = document.createElement('script'); 97 buwanaScript.src = `../translations/buwana-terms-${lang}.js?v=${version}`; 98 buwanaScript.onload = scriptLoaded; 99 document.head.appendChild(buwanaScript); 100} 101 102 103 104 105 106 107function clearSiteCache() { 108 // Translations for the confirm message 109 const confirmMessages = { 110 en: 'Do you wish to delete your language and site settings for ecobricks.org?', 111 fr: 'Souhaitez-vous supprimer vos paramètres de langue et de site pour ecobricks.org?', 112 es: '¿Desea eliminar la configuración de idioma y sitio para ecobricks.org?', 113 id: 'Apakah Anda ingin menghapus pengaturan bahasa dan situs untuk ecobricks.org?' 114 }; 115 116 // Translations for the alert message 117 const alertMessages = { 118 en: 'All site cache items are now cleared.', 119 fr: 'Tous les éléments du cache du site sont maintenant effacés.', 120 es: 'Todos los elementos en caché del sitio ahora están borrados.', 121 id: 'Semua item cache situs sekarang dibersihkan.' 122 }; 123 124 // Check the currentLanguage global variable, default to 'en' if undefined 125 const language = window.currentLanguage || 'en'; 126 127 // Use confirm message based on currentLanguage or default to English 128 const confirmMessage = confirmMessages[language] || confirmMessages.en; 129 130 // Show confirm dialog 131 if (confirm(confirmMessage)) { 132 // Clear local storage if user confirms 133 localStorage.clear(); 134 135 // Use alert message based on currentLanguage or default to English 136 const alertMessage = alertMessages[language] || alertMessages.en; 137 138 // Show alert dialog 139 alert(alertMessage); 140 } 141} 142 143 144function applyTranslations() { 145 const elements = document.querySelectorAll('[data-lang-id]');
146 elements.forEach(el => { 147 const key = el.getAttribute('data-lang-id'); 148 if (translations[key]) { 149 if (el.placeholder !== undefined) { 150 el.placeholder = translations[key]; 151 } else if (el.tagName.toLowerCase() === 'option') { 152 el.textContent = translations[key]; 153 } else { 154 el.innerHTML = translations[key]; 155 } 156 } 157 }); 158}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.