From d7df96279970e1b9db845bd7246733a7ff2101db Mon Sep 17 00:00:00 2001 From: Au Huishan Date: Sun, 3 Nov 2024 15:31:02 +0800 Subject: [PATCH 1/6] Added translation script and language switcher for book details --- fs.html | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 54 insertions(+), 4 deletions(-) diff --git a/fs.html b/fs.html index 85155d6..13a321a 100644 --- a/fs.html +++ b/fs.html @@ -129,6 +129,7 @@ + @@ -252,12 +253,12 @@ /> -
-

+
+

Frankestine

-

By Mary Shelby

-

+

By Mary Shelley

+

Frankenstein tells the story of Victor Frankenstein, a scientist who creates a monstrous creature, leading to tragic @@ -745,5 +746,54 @@

By Mary Shelby

integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous" > + + + + + From 4d96b07fdb444bc119a38bcfef72b859a2b2e3f7 Mon Sep 17 00:00:00 2001 From: Au Huishan Date: Sun, 3 Nov 2024 17:45:36 +0800 Subject: [PATCH 2/6] Add translations for Frankenstein book in English and Chinese --- fs.html | 47 ---------------------------------- translation.js | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 47 deletions(-) create mode 100644 translation.js diff --git a/fs.html b/fs.html index 13a321a..c40adf1 100644 --- a/fs.html +++ b/fs.html @@ -746,54 +746,7 @@

By Mary Shelley

integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous" > - - - diff --git a/translation.js b/translation.js new file mode 100644 index 0000000..9b8f8df --- /dev/null +++ b/translation.js @@ -0,0 +1,69 @@ +// translations.js + +// Translation Script +const translations = { + en: { + books: { + frankenstein: { + title: "Frankenstein", + author: "By Mary Shelley", + description: "Frankenstein tells the story of Victor Frankenstein, a scientist who creates a monstrous creature, leading to tragic consequences.", + } + } + }, + zh: { + books: { + frankenstein: { + title: "弗兰肯斯坦", + author: "玛丽·雪莱", + description: "《弗兰肯斯坦》讲述了科学家维克多·弗兰肯斯坦创造了一个怪物,导致悲剧性后果的故事。", + } + } + } + }; + + console.log('Translations object:', translations); + + function changeLanguage() { + const selectedLanguage = document.getElementById('language').value; + console.log('Selected language:', selectedLanguage); + applyTranslations(selectedLanguage); + } + + function applyTranslations(language) { + const bookElements = document.querySelectorAll('[data-book]'); + bookElements.forEach(bookElement => { + const bookKey = bookElement.getAttribute('data-book'); + console.log('Book key:', bookKey); + if (translations[language] && translations[language].books && translations[language].books[bookKey]) { + const bookTranslations = translations[language].books[bookKey]; + console.log('Applying translations for:', bookKey, bookTranslations); + bookElement.querySelector('[data-translate="title"]').innerText = bookTranslations.title; + bookElement.querySelector('[data-translate="author"]').innerText = bookTranslations.author; + bookElement.querySelector('[data-translate="description"]').innerText = bookTranslations.description; + + // Apply track translations + const trackElements = bookElement.querySelectorAll('[data-translate]'); + trackElements.forEach(trackElement => { + const trackKey = trackElement.getAttribute('data-translate'); + if (bookTranslations.tracks && bookTranslations.tracks[trackKey]) { + trackElement.innerText = bookTranslations.tracks[trackKey]; + } + }); + } else { + console.error('Translation not found for:', language, bookKey); + } + }); + } + + document.addEventListener('DOMContentLoaded', function() { + const defaultLanguage = 'en'; + console.log('Default language:', defaultLanguage); + applyTranslations(defaultLanguage); + }); + + document.getElementById('language').addEventListener('change', function() { + const selectedLanguage = this.value; + console.log('Selected language:', selectedLanguage); + applyTranslations(selectedLanguage); + }); \ No newline at end of file From b21b6230f5987cbbd6af2a08bbf696140685cf74 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 3 Nov 2024 09:46:30 +0000 Subject: [PATCH 3/6] docs(contributor): contrib-readme-action has updated readme --- README.md | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 428aa14..d1fdb30 100644 --- a/README.md +++ b/README.md @@ -167,6 +167,13 @@ MIT License Chinmay Ingale + + + AkierRaee +
+ Au Huishan +
+ username-amarjit @@ -195,6 +202,8 @@ MIT License Prathmesh Modhe + + Vedantjn @@ -202,8 +211,6 @@ MIT License Nirmohi - - aliabbasnagari From d172343b5509b03d0ea96a1622643b638894b50e Mon Sep 17 00:00:00 2001 From: Au Huishan Date: Sun, 3 Nov 2024 18:04:07 +0800 Subject: [PATCH 4/6] Add translations for Frankenstein book in English and Chinese --- fs.html | 1 + translation.js | 119 +++++++++++++++++++++++++------------------------ 2 files changed, 62 insertions(+), 58 deletions(-) diff --git a/fs.html b/fs.html index c40adf1..c8d17a1 100644 --- a/fs.html +++ b/fs.html @@ -741,6 +741,7 @@

By Mary Shelley

+