From e7c21ffbd7e51341c6c1098cdf8b6d4ffa0a848a Mon Sep 17 00:00:00 2001
From: FloatingGhost <hannah@coffee-and-dreams.uk>
Date: Mon, 29 Aug 2022 22:16:59 +0100
Subject: [PATCH] allow selecting languages for translation

---
 src/components/extra_buttons/extra_buttons.js          |  3 ++-
 .../interface_language_switcher.vue                    | 10 +++++++++-
 src/components/settings_modal/tabs/general_tab.js      | 10 ++++++++++
 src/components/settings_modal/tabs/general_tab.vue     | 10 ++++++++++
 src/i18n/en.json                                       |  1 +
 src/modules/config.js                                  |  3 ++-
 6 files changed, 34 insertions(+), 3 deletions(-)

diff --git a/src/components/extra_buttons/extra_buttons.js b/src/components/extra_buttons/extra_buttons.js
index 97fb7d6e..16841539 100644
--- a/src/components/extra_buttons/extra_buttons.js
+++ b/src/components/extra_buttons/extra_buttons.js
@@ -57,7 +57,8 @@ const ExtraButtons = {
     },
 
     translateStatus () {
-      this.$store.dispatch('translateStatus', { id: this.status.id, language: this.$store.state.instance.interfaceLanguage })
+      const translateTo = this.$store.getters.mergedConfig.translationLanguage || this.$store.state.instance.interfaceLanguage
+      this.$store.dispatch('translateStatus', { id: this.status.id, language: translateTo })
         .then(() => this.$emit('onSuccess'))
         .catch(err => this.$emit('onError', err.error.error))
     },
diff --git a/src/components/interface_language_switcher/interface_language_switcher.vue b/src/components/interface_language_switcher/interface_language_switcher.vue
index e46bcf71..e9ebb97a 100644
--- a/src/components/interface_language_switcher/interface_language_switcher.vue
+++ b/src/components/interface_language_switcher/interface_language_switcher.vue
@@ -1,6 +1,10 @@
 <template>
   <div>
-    <FAIcon icon="globe" /> {{ ' ' }}
+    <FAIcon
+      v-if="globeIcon"
+      icon="globe"
+    />
+    {{ ' ' }}
     <label for="interface-language-switcher">
       {{ promptText }}
     </label>
@@ -40,6 +44,10 @@ export default {
     setLanguage: {
       type: Function,
       required: true
+    },
+    globeIcon: {
+      type: Boolean,
+      default: true
     }
   },
   computed: {
diff --git a/src/components/settings_modal/tabs/general_tab.js b/src/components/settings_modal/tabs/general_tab.js
index 981da55b..39d9b31e 100644
--- a/src/components/settings_modal/tabs/general_tab.js
+++ b/src/components/settings_modal/tabs/general_tab.js
@@ -50,6 +50,7 @@ const GeneralTab = {
       Object.getOwnPropertyDescriptor(HTMLMediaElement.prototype, 'webkitAudioDecodedByteCount') ||
       // Future spec, still not supported in Nightly 63 as of 08/2018
       Object.getOwnPropertyDescriptor(HTMLMediaElement.prototype, 'audioTracks')
+
     }
   },
   components: {
@@ -82,11 +83,20 @@ const GeneralTab = {
         this.$store.dispatch('setOption', { name: 'interfaceLanguage', value: val })
       }
     },
+    translationLanguage: {
+      get: function () { return this.$store.getters.mergedConfig.translationLanguage },
+      set: function (val) {
+        this.$store.dispatch('setOption', { name: 'translationLanguage', value: val })
+      }
+    },
     ...SharedComputedObject()
   },
   methods: {
     changeDefaultScope (value) {
       this.$store.dispatch('setServerSideOption', { name: 'defaultScope', value })
+    },
+    setTranslationLanguage (value) {
+      this.$store.dispatch('setOption', { name: 'translationLanguage', value })
     }
   }
 }
diff --git a/src/components/settings_modal/tabs/general_tab.vue b/src/components/settings_modal/tabs/general_tab.vue
index 1e696d1a..3a8d5157 100644
--- a/src/components/settings_modal/tabs/general_tab.vue
+++ b/src/components/settings_modal/tabs/general_tab.vue
@@ -156,6 +156,16 @@
             </li>
           </ul>
         </li>
+        <li>
+          <p>
+            <interface-language-switcher
+              :globe-icon="false"
+              :prompt-text="$t('settings.translation_language')"
+              :language="translationLanguage"
+              :set-language="setTranslationLanguage"
+            />
+          </p>
+        </li>
         <li>
           <BooleanSetting
             path="alwaysShowNewPostButton"
diff --git a/src/i18n/en.json b/src/i18n/en.json
index 3671a2a2..ef2586fb 100644
--- a/src/i18n/en.json
+++ b/src/i18n/en.json
@@ -794,6 +794,7 @@
         "third_column_mode_postform": "Main post form and navigation",
         "token": "Token",
         "tooltipRadius": "Tooltips/alerts",
+        "translation_language": "Automatic Translation Language",
         "tree_advanced": "Allow more flexible navigation in tree view",
         "tree_fade_ancestors": "Display ancestors of the current post in faint text",
         "type_domains_to_mute": "Search domains to mute",
diff --git a/src/modules/config.js b/src/modules/config.js
index 789c0640..0ccdfc99 100644
--- a/src/modules/config.js
+++ b/src/modules/config.js
@@ -114,7 +114,8 @@ export const defaultState = {
   conversationTreeAdvanced: undefined, // instance default
   conversationOtherRepliesButton: undefined, // instance default
   conversationTreeFadeAncestors: undefined, // instance default
-  maxDepthInThread: undefined // instance default
+  maxDepthInThread: undefined, // instance default
+  translationLanguage: undefined // instance default
 }
 
 // caching the instance default properties