add the supporting to machine translation

This commit is contained in:
Zhigang Wang 2024-06-14 13:22:15 -07:00
parent 749d0fe47f
commit cc194be0d6
4 changed files with 37 additions and 10 deletions

View File

@ -1,9 +1,11 @@
<template> <template>
<div class="input_containter"> <div class="input_containter">
<input type="text" v-model="input_text"> <input type="text" v-model="input_text" @keyup.enter="translate($event)">
<p>{{ translated_text }}</p>
</div> </div>
</template> </template>
<script> <script>
import { LabApi } from '../../../utils/index'
export default { export default {
name: 'TranslationHome', name: 'TranslationHome',
components: {}, components: {},
@ -11,16 +13,23 @@ export default {
mounted() { mounted() {
}, },
methods: { methods: {
translate(text) { translate($event) {
this.mnx_navToLink((directory.path)) LabApi.translate_text(this.input_text)
.then((response) => {
this.translated_text = response.data
})
.catch((error) => {
this.mnx_backendErrorHandler(error)
})
} }
}, },
data() { data() {
return { return {
input_text: null input_text: null,
translated_text: null
}
} }
} }
}
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">

View File

@ -6,3 +6,4 @@ export { ProviderHubApi } from './providerHub'
export { MessageHubApi } from './messageHub' export { MessageHubApi } from './messageHub'
export { HistoryApi } from './history' export { HistoryApi } from './history'
export { ContentApi } from './content' export { ContentApi } from './content'
export { LabApi } from './lab'

View File

@ -0,0 +1,16 @@
import { backendAxios } from './axios'
import { userUtils } from '../store/index'
class LabApi {
static translate_text(input_text) {
let jwt = userUtils.getJwtToken()
const request = backendAxios.post('/api/lab/translate_text',
{
input_text: input_text
},
{
headers: { Authorization: `Bearer ${jwt}` }
})
return request
}
}
export { LabApi }

View File

@ -6,7 +6,8 @@ export {
ProviderHubApi, ProviderHubApi,
MessageHubApi, MessageHubApi,
HistoryApi, HistoryApi,
ContentApi ContentApi,
LabApi
} from './backend/index' } from './backend/index'
export { userUtils, userProfileUtils, requestIssueUtils, requestHubUtils } from './store/index' export { userUtils, userProfileUtils, requestIssueUtils, requestHubUtils } from './store/index'