aboutsummaryrefslogtreecommitdiff
path: root/static
diff options
context:
space:
mode:
Diffstat (limited to 'static')
-rw-r--r--static/js/globals.js7
-rw-r--r--static/js/tl.js53
2 files changed, 43 insertions, 17 deletions
diff --git a/static/js/globals.js b/static/js/globals.js
index ad0f4518..9100251b 100644
--- a/static/js/globals.js
+++ b/static/js/globals.js
@@ -7,8 +7,11 @@ gtag("js", new Date());
gtag("config", "G-72XTC500FR");
function changeLang(lang) {
- document.cookie = "lang=" + lang + "; expires=Fri, 31 Dec 9999 23:59:59 GMT; path=/";
- location.reload();
+ if (lang === "ja") {
+ translateJapanese();
+ } else {
+ restoreLang();
+ }
}
// Smooth scroll to anchor
diff --git a/static/js/tl.js b/static/js/tl.js
index 7eaf14a2..4cfdb7ff 100644
--- a/static/js/tl.js
+++ b/static/js/tl.js
@@ -9,31 +9,54 @@ function googleTranslateElementInit() {
);
}
-var currentLang = document.cookie.replace(
- /(?:(?:^|.*;\s*)lang\s*\=\s*([^;]*).*$)|^.*$/,
- "$1"
-);
-
-if (currentLang == "ja") {
- triggerTranslation("ja");
-} else {
- triggerTranslation("en");
+function restoreLang() {
+ localStorage.setItem("lang", "en");
+ $('#tl_ja').hide();
+ $('#tl_en').show();
+ var translateContainers = $('iframe');
+ if (translateContainers.length === 0) {
+ // nothing
+ } else {
+ translateContainers.each(function (index, element) {
+ if (element.contentWindow.document.getElementById(":1.restore")) {
+ console.log(element.contentWindow.document.getElementById(":1.restore"));
+ element.contentWindow.document.getElementById(":1.restore").click();
+ }
+ });
+ }
}
-function triggerTranslation(language) {
+function translateJapanese() {
+ localStorage.setItem("lang", "ja");
+ $('#tl_en').hide();
+ $('#tl_ja').show();
var selectEl = document.querySelector("select.goog-te-combo");
+ console.log(selectEl);
if (!selectEl) {
setTimeout(function () {
- triggerTranslation(language);
+ translateJapanese();
}, 10);
} else if (!selectEl.options || selectEl.options.length === 0) {
setTimeout(function () {
- triggerTranslation(language);
+ translateJapanese();
}, 10);
} else {
- selectEl.value = language;
+ selectEl.value = 'ja';
selectEl.dispatchEvent(new Event("change"));
- // visiblity of #main-section is hidden until translation is done, show it after translation is done
- document.getElementById("main-section").style.visibility = "visible";
}
}
+
+// init
+var currentLang = localStorage.getItem("lang");
+if (!currentLang) {
+ currentLang = "en";
+ localStorage.setItem("lang", "en");
+}
+if (currentLang === "ja") {
+ $('#tl_en').hide();
+ $('#tl_ja').show();
+} else {
+ $('#tl_ja').hide();
+ $('#tl_en').show();
+ restoreLang();
+}