Skip to content
Snippets Groups Projects
Unverified Commit bc115050 authored by gabriellsh's avatar gabriellsh Committed by GitHub
Browse files

fix(meteor): Autotranslate encoding message (#29625)

parent bc33bf5a
No related branches found
No related tags found
No related merge requests found
---
"@rocket.chat/meteor": patch
---
fixed a bug with autotranslation encoding text
...@@ -198,8 +198,7 @@ class DeeplAutoTranslate extends AutoTranslate { ...@@ -198,8 +198,7 @@ class DeeplAutoTranslate extends AutoTranslate {
*/ */
async _translateMessage(message: IMessage, targetLanguages: string[]): Promise<ITranslationResult> { async _translateMessage(message: IMessage, targetLanguages: string[]): Promise<ITranslationResult> {
const translations: { [k: string]: string } = {}; const translations: { [k: string]: string } = {};
let msgs = message.msg.split('\n'); const msgs = message.msg.split('\n');
msgs = msgs.map((msg) => encodeURIComponent(msg));
const supportedLanguages = await this.getSupportedLanguages('en'); const supportedLanguages = await this.getSupportedLanguages('en');
for await (let language of targetLanguages) { for await (let language of targetLanguages) {
if (language.indexOf('-') !== -1 && !_.findWhere(supportedLanguages, { language })) { if (language.indexOf('-') !== -1 && !_.findWhere(supportedLanguages, { language })) {
...@@ -250,7 +249,7 @@ class DeeplAutoTranslate extends AutoTranslate { ...@@ -250,7 +249,7 @@ class DeeplAutoTranslate extends AutoTranslate {
params: { params: {
auth_key: this.apiKey, auth_key: this.apiKey,
target_lang: language, target_lang: language,
text: encodeURIComponent(attachment.description || attachment.text || ''), text: attachment.description || attachment.text || '',
}, },
}); });
if (!result.ok) { if (!result.ok) {
......
...@@ -126,8 +126,6 @@ class GoogleAutoTranslate extends AutoTranslate { ...@@ -126,8 +126,6 @@ class GoogleAutoTranslate extends AutoTranslate {
*/ */
async _translateMessage(message: IMessage, targetLanguages: string[]): Promise<ITranslationResult> { async _translateMessage(message: IMessage, targetLanguages: string[]): Promise<ITranslationResult> {
const translations: { [k: string]: string } = {}; const translations: { [k: string]: string } = {};
let msgs = message.msg.split('\n');
msgs = msgs.map((msg) => encodeURIComponent(msg));
const supportedLanguages = await this.getSupportedLanguages('en'); const supportedLanguages = await this.getSupportedLanguages('en');
...@@ -142,7 +140,7 @@ class GoogleAutoTranslate extends AutoTranslate { ...@@ -142,7 +140,7 @@ class GoogleAutoTranslate extends AutoTranslate {
key: this.apiKey, key: this.apiKey,
target: language, target: language,
format: 'text', format: 'text',
q: msgs, q: message.msg.split('\n'),
}, },
}); });
if (!result.ok) { if (!result.ok) {
...@@ -189,7 +187,7 @@ class GoogleAutoTranslate extends AutoTranslate { ...@@ -189,7 +187,7 @@ class GoogleAutoTranslate extends AutoTranslate {
key: this.apiKey, key: this.apiKey,
target: language, target: language,
format: 'text', format: 'text',
q: encodeURIComponent(attachment.description || attachment.text || ''), q: attachment.description || attachment.text || '',
}, },
}); });
if (!result.ok) { if (!result.ok) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment