New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Translate chat messages #9512
Translate chat messages #9512
Conversation
8b15247
to
500de38
Compare
500de38
to
120eaae
Compare
src/components/MessagesList/MessagesGroup/Message/MessageButtonsBar/MessageButtonsBar.vue
Outdated
Show resolved
Hide resolved
So, i get a successful responce on axios.get(generateOcsUrl('/translation/languages')): But when trying to translate with axios.post(generateOcsUrl('/translation/translate'), get an error: |
Signed-off-by: Maksim Sukharev <antreesy.web@gmail.com>
120eaae
to
8497bd7
Compare
src/components/MessagesList/MessagesGroup/Message/MessageButtonsBar/MessageTranslateDialog.vue
Outdated
Show resolved
Hide resolved
src/components/MessagesList/MessagesGroup/Message/MessageButtonsBar/MessageTranslateDialog.vue
Outdated
Show resolved
Hide resolved
src/components/MessagesList/MessagesGroup/Message/MessageButtonsBar/MessageTranslateDialog.vue
Show resolved
Hide resolved
Signed-off-by: Maksim Sukharev <antreesy.web@gmail.com>
Signed-off-by: Maksim Sukharev <antreesy.web@gmail.com>
isTranslationAvailable: { | ||
type: Boolean, | ||
required: true, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the isTranslationAvailable
always supposed to have value from capabilities
?
If it is, maybe use capability instead of prop here? Or at least use capabilities as the default value. Then the long list of props to pass will be a little bit less 😀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be done later, when we'll finally reach Message refactoring =)
async translateMessage(sourceLanguage = null) { | ||
try { | ||
this.isLoading = true | ||
const response = await translateText(this.message, sourceLanguage, this.selectedTo?.id) | ||
this.translatedMessage = response.data.ocs.data.text | ||
} catch (error) { | ||
console.error(error) | ||
showError(error.response?.data?.ocs?.data?.message ?? t('spreed', 'The message could not be translated')) | ||
} finally { | ||
this.isLoading = false | ||
} | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the first modal open it always fails to me from the request in mounted
:
Request:
fetch("https://<HOST>/ocs/v2.php/translation/translate", {
"headers": {
"accept": "application/json, text/plain, */*",
"accept-language": "en-US,en;q=0.9,ru;q=0.8",
"content-type": "application/json",
"requesttoken": "<DELETED>",
"sec-ch-ua": "\"Chromium\";v=\"112\", \"Not:A-Brand\";v=\"99\"",
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": "\"Windows\"",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-origin"
},
"referrerPolicy": "no-referrer",
"body": "{\"text\":\"Hallo!\",\"fromLanguage\":null,\"toLanguage\":\"en\"}",
"method": "POST",
"mode": "cors",
"credentials": "include"
});
Response:
{"ocs":{"meta":{"status":"failure","statuscode":400,"message":""},"data":{"message":"Could not detect language"}}}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's on API side then, we always send text and 'to' language
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, it seems, API is used correctly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's what I said in the office. You send a single word and fromLanguage is null.
But on a single word language models don't work and respond with a language, so we don't have a from when talking to translations provider and it returns with could not translate
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should not show the error message in this case?
Otherwise, all small messages show an error toast on opening the translation modal.
Also, if only one language is available, we can pre-select it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well we could try to hide the error from empty runs yeah, but let's do that in a follow up
☑️ Resolves
Requisites
nextcloud/translate
and install according to Readme: https://github.com/nextcloud/translate🖼️ Screenshots
🚧 Tasks
🏁 Checklist
docs/
has been updated or is not required