aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBobby <[email protected]>2023-06-07 22:45:06 -0400
committerBobby <[email protected]>2023-06-07 22:45:06 -0400
commit2f3508ea23a9ce470fd6570235aa63e90e50df7f (patch)
treeda55a52fb4e953015b522377d21f0a4bcdfd58be
parent3b2f2278b14566e06209ffc4117e17221aedfe0a (diff)
downloadthatcomputerscientist-2f3508ea23a9ce470fd6570235aa63e90e50df7f.tar.xz
thatcomputerscientist-2f3508ea23a9ce470fd6570235aa63e90e50df7f.zip
Remove Middleware and Handle Translate Client Side
-rw-r--r--static/css/styles.css5
-rw-r--r--static/js/tl.js43
-rw-r--r--templates/blog/partials/base.html28
-rw-r--r--templates/blog/partials/sidebar.html4
-rw-r--r--templates/blog/post.html8
-rw-r--r--thatcomputerscientist/settings.py2
6 files changed, 75 insertions, 15 deletions
diff --git a/static/css/styles.css b/static/css/styles.css
index 061c7deb..491780c7 100644
--- a/static/css/styles.css
+++ b/static/css/styles.css
@@ -3,6 +3,7 @@
@import url('https://fonts.googleapis.com/css2?family=Mali:ital,wght@0,400;0,700;1,400;1,700&display=swap');
body {
+ position: unset !important;
width: 100%;
background: black;
font-size: 11px;
@@ -13,6 +14,10 @@ body {
box-sizing: border-box;
}
+.skiptranslate {
+ display: none !important;
+}
+
input,
textarea {
font-family: 'Mali', sans-serif !important;
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
+ }
+}
diff --git a/templates/blog/partials/base.html b/templates/blog/partials/base.html
index ddb12727..e194a6b6 100644
--- a/templates/blog/partials/base.html
+++ b/templates/blog/partials/base.html
@@ -62,6 +62,25 @@
white-space: nowrap; /* Prevent line breaks */
}
</style>
+ {% if request.COOKIES.lang == 'ja' %}
+ <script
+ type="text/javascript"
+ src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"
+ ></script>
+ <script src="{% static 'js/tl.js' %}"></script>
+ {% endif %}
+
+ <script src="{% static 'js/jquery-1.12.4.min.js' %}"></script>
+ <script src="{% static 'js/globals.js' %}"></script>
+ <script src="{% static 'js/phone_compatibility.js' %}"></script>
+ {% if request.COOKIES.summonOneko == 'true' %}
+ <script src="{% static 'js/oneko.js' %}"></script>
+ {% endif %} {% block scripts %} {% endblock %}
+ <!-- Google tag (gtag.js) -->
+ <script
+ async
+ src="https://www.googletagmanager.com/gtag/js?id=G-72XTC500FR"
+ ></script>
</head>
<body>
<video id="bg-video" muted autoplay playsinline loop preload="auto">
@@ -144,14 +163,5 @@
</p>
</div>
</div>
- <script src="{% static 'js/jquery-1.12.4.min.js' %}"></script>
- <script src="{% static 'js/globals.js' %}"></script>
- <script src="{% static 'js/phone_compatibility.js' %}"></script>
- {% if request.COOKIES.summonOneko == 'true' %}
- <script src="{% static 'js/oneko.js' %}"></script>
- {% endif %}
- {% block scripts %} {% endblock %}
- <!-- Google tag (gtag.js) -->
- <script async src="https://www.googletagmanager.com/gtag/js?id=G-72XTC500FR"></script>
</body>
</html>
diff --git a/templates/blog/partials/sidebar.html b/templates/blog/partials/sidebar.html
index 97f4d7f6..9699436b 100644
--- a/templates/blog/partials/sidebar.html
+++ b/templates/blog/partials/sidebar.html
@@ -361,4 +361,6 @@
</ul>
<p>(Based on users active over the past 5 minutes)</p>
</div>
-</div> \ No newline at end of file
+</div>
+<div id="google_translate_element"></div>
+
diff --git a/templates/blog/post.html b/templates/blog/post.html
index 7c0e6d3b..5466c465 100644
--- a/templates/blog/post.html
+++ b/templates/blog/post.html
@@ -106,7 +106,7 @@
</td>
<td style="vertical-align: top; width: 668px;">
<div style="margin-bottom: 13px; border-bottom: dashed 1px white; padding-bottom: 13px;">
- <a {% if comment.user%}href="{% url 'blog:user_activity' comment.user.username %}"{% endif %}>{% if comment.user %}{{ comment.user.username }}{% else %}{{ comment.anonymous_user.name }}{% endif %}</a> on <em>{{ comment.created_at | date:"M d, Y" }}</em>
+ <a class="notranslate" {% if comment.user%}href="{% url 'blog:user_activity' comment.user.username %}"{% endif %}>{% if comment.user %}{{ comment.user.username }}{% else %}{{ comment.anonymous_user.name }}{% endif %}</a> on <em>{{ comment.created_at | date:"M d, Y" }}</em>
{% if comment.edited %}
<em>(Edited)</em>
{% endif %}
@@ -123,7 +123,7 @@
<a href="{% url 'blog:anon_delete_comment' post.slug comment.id %}" onclick="return confirm('Are you sure you want to delete this comment?')">Delete</a>
{% endif %}
</div>
- <div id="comment-body-{{ comment.id }}" class="comment">
+ <div id="comment-body-{{ comment.id }}" class="comment notranslate">
{{ comment.processed_body|safe }}
</div>
{% if comment.user == user %}
@@ -131,7 +131,7 @@
<form action="{% url 'blog:edit_comment' post.slug %}" method="POST">
{% csrf_token %}
<input type = "hidden" name="comment_id" value="{{ comment.id }}">
- <textarea name="body" id="body" cols="78" rows="10" style="width: 640px; display: block; margin-bottom: 10px;">{{ comment.body }}</textarea>
+ <textarea class="notranslate" name="body" id="body" cols="78" rows="10" style="width: 640px; display: block; margin-bottom: 10px;">{{ comment.body }}</textarea>
<input type="submit" value="Update" class="button button-special">
<input type="button" value="Cancel" onclick="cancelEdit({{ comment.id }})" class="button">
</form>
@@ -142,7 +142,7 @@
<form action="{% url 'blog:anon_edit_comment' post.slug %}" method="POST">
{% csrf_token %}
<input type = "hidden" name="comment_id" value="{{ comment.id }}">
- <textarea name="body" id="body" cols="78" rows="10" style="width: 640px; display: block; margin-bottom: 10px;">{{ comment.body }}</textarea>
+ <textarea class="notranslate" name="body" id="body" cols="78" rows="10" style="width: 640px; display: block; margin-bottom: 10px;">{{ comment.body }}</textarea>
<input type="submit" value="Update" class="button button-special">
<input type="button" value="Cancel" onclick="cancelEdit({{ comment.id }})" class="button">
</form>
diff --git a/thatcomputerscientist/settings.py b/thatcomputerscientist/settings.py
index 7c24b42f..a7569fba 100644
--- a/thatcomputerscientist/settings.py
+++ b/thatcomputerscientist/settings.py
@@ -87,7 +87,7 @@ MIDDLEWARE = [
'middleware.oldbrowsermiddleware.OldBrowserMiddleware',
'middleware.globalmetamiddleware.GlobalMetaMiddleware',
'middleware.uuidmiddleware.UserUUIDMiddleware',
- 'middleware.translationMiddleware.TranslationMiddleware',
+ # 'middleware.translationMiddleware.TranslationMiddleware',
]
CONFIGURED_SUBDOMAINS = {