Skip to content

Commit

Permalink
update language switching bug
Browse files Browse the repository at this point in the history
  • Loading branch information
AkierRaee committed Nov 8, 2024
1 parent 8f15350 commit 7768b06
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions gd.html
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
<div class="language-selector">
<select
id="language"
onchange="changeLanguage()"
onchange="changeLanguageLocally()"
style="background-color: #1db954; color: #fff"
>
<option value="en">English</option>
Expand Down Expand Up @@ -799,6 +799,12 @@ <h3 class="text-lg mt-2" data-translate="author">By Richard Dawkins</h3>

<!-- Ensure language sync in iframe -->
<script>
function changeLanguageLocally() {
const language = document.getElementById('language').value;
console.log('Local language change in gd.html:', language);
applyTranslations(language); // Directly apply translations within gd.html
}

function changeLanguage(language) {
applyTranslations(language); // Call the translation function from translation.js
}
Expand All @@ -810,10 +816,16 @@ <h3 class="text-lg mt-2" data-translate="author">By Richard Dawkins</h3>
// Listener for postMessage from index.html
window.addEventListener('message', (event) => {
if (event.data.type === 'changeLanguage') {
const language = event.data.language;
applyTranslations(language);
const language = event.data.language;
console.log('Message received in gd.html, applying translations for language:', language);
applyTranslations(language);
}
});

document.addEventListener('DOMContentLoaded', function() {
const defaultLanguage = 'en';
applyTranslations(defaultLanguage);
});
</script>

</body>
Expand Down

0 comments on commit 7768b06

Please sign in to comment.