diff options
| author | Bobby <[email protected]> | 2023-06-07 22:45:06 -0400 |
|---|---|---|
| committer | Bobby <[email protected]> | 2023-06-07 22:45:06 -0400 |
| commit | 2f3508ea23a9ce470fd6570235aa63e90e50df7f (patch) | |
| tree | da55a52fb4e953015b522377d21f0a4bcdfd58be /static/js | |
| parent | 3b2f2278b14566e06209ffc4117e17221aedfe0a (diff) | |
| download | thatcomputerscientist-2f3508ea23a9ce470fd6570235aa63e90e50df7f.tar.xz thatcomputerscientist-2f3508ea23a9ce470fd6570235aa63e90e50df7f.zip | |
Remove Middleware and Handle Translate Client Side
Diffstat (limited to 'static/js')
| -rw-r--r-- | static/js/tl.js | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/static/js/tl.js b/static/js/tl.js new file mode 100644 index 00000000..98bd9529 --- /dev/null +++ b/static/js/tl.js @@ -0,0 +1,43 @@ +// Google Translate (Only English and Japanese) +function googleTranslateElementInit() { + new google.translate.TranslateElement( + { + pageLanguage: "en", + includedLanguages: "ja", + }, + "google_translate_element" + ); +} + +var currentLang = document.cookie.replace( + /(?:(?:^|.*;\s*)lang\s*\=\s*([^;]*).*$)|^.*$/, + "$1" +); + +console.log("currentLang: " + currentLang); + +if (currentLang == "ja") { + triggerTranslation("ja"); +} else { + triggerTranslation("en"); +} + +function triggerTranslation(language) { + var selectEl = document.querySelector("select.goog-te-combo"); + if (!selectEl) { + setTimeout(function () { + triggerTranslation(language); + }, 100); + } else if (!selectEl.options || selectEl.options.length === 0) { + setTimeout(function () { + triggerTranslation(language); + }, 100); + } else { + console.log("triggering translation"); + console.log(selectEl.options, selectEl.options.length); // HTMLOptionsCollection with options + + // Continue with the logic for handling the available options + selectEl.value = language; // Change the value of the select element + selectEl.dispatchEvent(new Event("change")); // Trigger change event + } +} |
