diff --git a/src/components/MenuEnvelope.vue b/src/components/MenuEnvelope.vue index 09745993cb..402e682bbb 100644 --- a/src/components/MenuEnvelope.vue +++ b/src/components/MenuEnvelope.vue @@ -83,7 +83,7 @@ {{ t('mail', 'Unsnooze') }} - @@ -317,7 +315,6 @@ import moment from '@nextcloud/moment' import { translateTagDisplayName } from '../util/tag.js' import { FOLLOW_UP_TAG_LABEL } from '../store/constants.js' import { Text, toPlain } from '../util/text.js' -import { getTranslationLanguages } from '../service/translationService.js' // Ternary loading state const LOADING_DONE = 0 @@ -415,7 +412,6 @@ export default { rawMessage: '', // Will hold the raw source of the message when requested isInternal: true, enabledSmartReply: loadState('mail', 'llm_freeprompt_available', false), - availableTranslationLanguages: [], } }, computed: { @@ -618,10 +614,6 @@ export default { clearInterval(this.$checkInterval) } }, 100) - - const response = await getTranslationLanguages() - this.availableTranslationLanguages = response.data.ocs.data.languages - console.log('availableTranslationLanguages', this.availableTranslationLanguages) }, beforeDestroy() { if (this.seenTimer !== undefined) { diff --git a/src/components/TranslationModal.vue b/src/components/TranslationModal.vue index 025d22b529..f28e986607 100644 --- a/src/components/TranslationModal.vue +++ b/src/components/TranslationModal.vue @@ -75,6 +75,7 @@ import { showError, showSuccess } from '@nextcloud/dialogs' import { NcButton, NcDialog, NcLoadingIcon, NcRichText, NcSelect } from '@nextcloud/vue' import { translateText } from '../service/translationService.js' +import { mapGetters } from 'vuex' export default { name: 'TranslationModal', @@ -99,10 +100,6 @@ export default { type: Object, required: true, }, - availableLanguages: { - type: Array, - required: true, - }, }, emits: ['close'], @@ -118,6 +115,10 @@ export default { }, computed: { + ...mapGetters({ + availableLanguages: 'getTranslationLanguages', + }), + userLanguage() { return navigator.language.substring(0, 2) }, diff --git a/src/main.js b/src/main.js index b5030c72a7..ca72a2618e 100644 --- a/src/main.js +++ b/src/main.js @@ -22,6 +22,7 @@ import { fixAccountId } from './service/AccountService.js' import { loadState } from '@nextcloud/initial-state' import { createPinia, PiniaVuePlugin } from 'pinia' import useOutboxStore from './store/outboxStore.js' +import { checkTranslationServiceAvailability } from './service/translationService.js' Vue.use(PiniaVuePlugin) const pinia = createPinia() @@ -145,6 +146,8 @@ store.commit('setFollowUpFeatureAvailable', followUpFeatureAvailable) const smimeCertificates = loadState('mail', 'smime-certificates', []) store.commit('setSmimeCertificates', smimeCertificates) +checkTranslationServiceAvailability() + /* eslint-disable vue/match-component-file-name */ export default new Vue({ el: '#content', diff --git a/src/service/translationService.js b/src/service/translationService.js index 89fa15531a..1712bc2ebc 100644 --- a/src/service/translationService.js +++ b/src/service/translationService.js @@ -5,9 +5,38 @@ import axios from '@nextcloud/axios' import { generateOcsUrl } from '@nextcloud/router' +import store from '../store/index.js' -const getTranslationLanguages = async function(options) { - return axios.get(generateOcsUrl('/translation/languages', undefined, options), options) +const checkTranslationServiceAvailability = function() { + /// TODO + // const response = await axios.post(generateOcsUrl('taskprocessing/tasktypes'), { + // appId: 'mail', + // }) + + const isAvailable = true + const languages = [ + { + from: 'en', + fromLabel: 'English', + to: 'fr', + toLabel: 'French', + }, + { + from: 'en', + fromLabel: 'English', + to: 'de', + toLabel: 'German', + }, + { + from: 'fr', + fromLabel: 'French', + to: 'en', + toLabel: 'English', + }, + ] + + store.commit('enableTranslation', isAvailable) + store.commit('setTranslationLanguages', languages) } const translateText = async function(text, fromLanguage, toLanguage) { @@ -36,4 +65,4 @@ const translateText = async function(text, fromLanguage, toLanguage) { } } -export { getTranslationLanguages, translateText } +export { checkTranslationServiceAvailability, translateText } diff --git a/src/store/getters.js b/src/store/getters.js index f0b8351b88..48aa3d3d02 100644 --- a/src/store/getters.js +++ b/src/store/getters.js @@ -160,4 +160,6 @@ export const getters = { getInternalAddresses: (state) => state.internalAddress?.filter(internalAddress => internalAddress !== undefined), hasCurrentUserPrincipalAndCollections: (state) => state.hasCurrentUserPrincipalAndCollections, showSettingsForAccount: (state) => (accountId) => state.showAccountSettings === accountId, + isTranslationEnabled: (state) => state.isTranslationEnabled, + getTranslationLanguages: (state) => state.translationLanguages, } diff --git a/src/store/index.js b/src/store/index.js index 55bfb36d5a..862044933e 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -109,6 +109,8 @@ export default new Store({ internalAddress: [], hasCurrentUserPrincipalAndCollections: false, showAccountSettings: null, + isTranslationEnabled: false, + translationLanguages: [], }, getters, mutations, diff --git a/src/store/mutations.js b/src/store/mutations.js index 60214361e5..e599d52409 100644 --- a/src/store/mutations.js +++ b/src/store/mutations.js @@ -519,4 +519,10 @@ export default { showSettingsForAccount(state, accountId) { state.showAccountSettings = accountId }, + enableTranslation(state, enabled) { + state.isTranslationEnabled = enabled + }, + setTranslationLanguages(state, languages) { + state.translationLanguages = languages + }, }