allow translating to any other language

This commit is contained in:
FloatingGhost 2022-08-30 15:43:57 +01:00
parent ef50c63dc7
commit 6440e51b7e
6 changed files with 40 additions and 7 deletions

View file

@ -9,6 +9,7 @@ import {
faLink, faLink,
faPollH faPollH
} from '@fortawesome/free-solid-svg-icons' } from '@fortawesome/free-solid-svg-icons'
import Select from 'src/components/select/select.vue'
library.add( library.add(
faFile, faFile,
@ -39,7 +40,8 @@ const StatusContent = {
return { return {
postLength: this.status.text.length, postLength: this.status.text.length,
parseReadyDone: false, parseReadyDone: false,
renderMisskeyMarkdown renderMisskeyMarkdown,
translateFrom: null
} }
}, },
computed: { computed: {
@ -80,10 +82,14 @@ const StatusContent = {
attachmentTypes () { attachmentTypes () {
return this.status.attachments.map(file => fileType.fileType(file.mimetype)) return this.status.attachments.map(file => fileType.fileType(file.mimetype))
}, },
translationLanguages () {
return (this.$store.getters.mergedConfig.supportedTranslationLanguages || []).map(lang => ({ key: lang.code, value: lang.code, label: lang.name }))
},
...mapGetters(['mergedConfig']) ...mapGetters(['mergedConfig'])
}, },
components: { components: {
RichContent RichContent,
Select
}, },
mounted () { mounted () {
this.status.attentions && this.status.attentions.forEach(attn => { this.status.attentions && this.status.attentions.forEach(attn => {
@ -126,6 +132,10 @@ const StatusContent = {
}, },
generateTagLink (tag) { generateTagLink (tag) {
return `/tag/${tag}` return `/tag/${tag}`
},
translateStatus () {
const translateTo = this.$store.getters.mergedConfig.translationLanguage || this.$store.state.instance.interfaceLanguage
this.$store.dispatch('translateStatus', { id: this.status.id, language: translateTo, from: this.translateFrom })
} }
} }
} }

View file

@ -72,6 +72,27 @@
:attentions="status.attentions" :attentions="status.attentions"
@parseReady="onParseReady" @parseReady="onParseReady"
/> />
<div>
<label class="label">{{ $t('status.override_translation_source_language') }}</label>
{{ ' ' }}
<Select
id="source-language-switcher"
v-model="translateFrom"
class="preset-switcher"
>
<option
v-for="language in translationLanguages"
:key="language.key"
:value="language.value"
>
{{ language.label }}
</option>
</Select>
{{ ' ' }}
<button @click="translateStatus" class="btn button-default">
{{ $t('status.translate') }}
</button>
</div>
</div> </div>
</div> </div>
<button <button

View file

@ -846,6 +846,7 @@
"mute_conversation": "Mute conversation", "mute_conversation": "Mute conversation",
"nsfw": "NSFW", "nsfw": "NSFW",
"open_gallery": "Open gallery", "open_gallery": "Open gallery",
"override_translation_source_language": "Override source language",
"pin": "Pin on profile", "pin": "Pin on profile",
"pinned": "Pinned", "pinned": "Pinned",
"plus_more": "+{number} more", "plus_more": "+{number} more",

View file

@ -255,7 +255,7 @@ const api = {
getSupportedTranslationlanguages (store) { getSupportedTranslationlanguages (store) {
store.state.backendInteractor.getSupportedTranslationlanguages({ store }) store.state.backendInteractor.getSupportedTranslationlanguages({ store })
.then((data) => { .then((data) => {
store.dispatch('setInstanceOption', { name: 'supportedTranslationLanguages', value: data }) store.dispatch('setOption', { name: 'supportedTranslationLanguages', value: data })
}) })
}, },

View file

@ -641,8 +641,8 @@ const statuses = {
rootState.api.backendInteractor.unpinOwnStatus({ id: statusId }) rootState.api.backendInteractor.unpinOwnStatus({ id: statusId })
.then((status) => dispatch('addNewStatuses', { statuses: [status] })) .then((status) => dispatch('addNewStatuses', { statuses: [status] }))
}, },
translateStatus ({ rootState, commit }, { id, translation, language }) { translateStatus ({ rootState, commit }, { id, translation, language, from }) {
return rootState.api.backendInteractor.translateStatus({ id: id, translation, language }) return rootState.api.backendInteractor.translateStatus({ id: id, translation, language, from })
.then((translation) => commit('setTranslatedStatus', { id, translation })) .then((translation) => commit('setTranslatedStatus', { id, translation }))
}, },
muteConversation ({ rootState, commit }, statusId) { muteConversation ({ rootState, commit }, statusId) {

View file

@ -744,8 +744,9 @@ const getSupportedTranslationlanguages = ({ credentials }) => {
return promisedRequest({ url: AKKOMA_LANGUAGES_URL, credentials }) return promisedRequest({ url: AKKOMA_LANGUAGES_URL, credentials })
} }
const translateStatus = ({ id, credentials, language }) => { const translateStatus = ({ id, credentials, language, from }) => {
return promisedRequest({ url: AKKOMA_TRANSLATE_URL(id, language), method: 'GET', credentials }) const queryString = from ? `?from=${from}` : ''
return promisedRequest({ url: AKKOMA_TRANSLATE_URL(id, language) + queryString, method: 'GET', credentials })
.then((data) => { .then((data) => {
return data return data
}) })