From 8f88e859538c6bae3fa79c7c1418b3c278f9f871 Mon Sep 17 00:00:00 2001 From: Jeff Emmett Date: Wed, 9 Apr 2025 16:36:25 -0700 Subject: [PATCH] fix translations --- css/styles.css | 4 ++-- js/translations.js | 30 ++++++++++-------------------- 2 files changed, 12 insertions(+), 22 deletions(-) diff --git a/css/styles.css b/css/styles.css index 07b5d49..ba78746 100644 --- a/css/styles.css +++ b/css/styles.css @@ -104,7 +104,7 @@ header { display: flex; justify-content: space-between; align-items: center; - padding: 1rem 0; + padding: 0.75rem 0; direction: ltr !important; } @@ -170,7 +170,7 @@ header { justify-content: center; color: white; text-align: center; - margin-top: 80px; + margin-top: 60px; } .page-banner h1 { diff --git a/js/translations.js b/js/translations.js index 4d3bcbe..f19cb68 100644 --- a/js/translations.js +++ b/js/translations.js @@ -51,7 +51,6 @@ let currentLanguage = 'en'; function toggleLanguage() { currentLanguage = currentLanguage === 'en' ? 'ar' : 'en'; - // Update the language toggle text const langText = document.getElementById('langText'); if (langText) { langText.textContent = currentLanguage === 'en' ? 'EN / عربي' : 'عربي / EN'; @@ -60,15 +59,12 @@ function toggleLanguage() { // Update text direction for Arabic, excluding header if (currentLanguage === 'ar') { document.documentElement.dir = 'rtl'; - // Add RTL class to main content areas only document.querySelectorAll('main, section, footer').forEach(element => { element.style.direction = 'rtl'; }); - // Keep header LTR document.querySelector('header').style.direction = 'ltr'; } else { document.documentElement.dir = 'ltr'; - // Remove RTL from all elements document.querySelectorAll('main, section, footer').forEach(element => { element.style.direction = 'ltr'; }); @@ -82,25 +78,19 @@ function translatePage() { elements.forEach(element => { const key = element.getAttribute('data-translate'); - - // Get translations from all translation files - const translations = { - ...homeTranslations, - ...aboutTranslations, - ...workTranslations, - ...supportTranslations, - ...contactTranslations - }; - - // Update text content if translation exists if (translations[currentLanguage] && translations[currentLanguage][key]) { element.textContent = translations[currentLanguage][key]; } }); } -// Don't automatically translate on page load -// document.addEventListener('DOMContentLoaded', translatePage); - -// Add click handler to language toggle -document.querySelector('.language-toggle').addEventListener('click', toggleLanguage); \ No newline at end of file +// Remove onclick attribute from HTML and use event listener +document.addEventListener('DOMContentLoaded', () => { + const langToggle = document.querySelector('.language-toggle'); + if (langToggle) { + // Remove existing onclick attribute + langToggle.removeAttribute('onclick'); + // Add click event listener + langToggle.addEventListener('click', toggleLanguage); + } +}); \ No newline at end of file