RocketChat / Rocket.Chat

The communications platform that puts data protection first.
https://rocket.chat/
Other
40.09k stars 10.35k forks source link

Auto Translate shows placeholders for notranslate parts in the chat #31146

Open robinreckmann opened 9 months ago

robinreckmann commented 9 months ago

Description:

When using auto translate, parts of a chat message that are not supposed to be translated (like @ user xy) are shown as placeholders.

Steps to reproduce:

Enable auto translate for a room and send a message that includes notranslate parts like @ user xy. In our case, we are using Microsoft auto translate services.

Expected behavior:

The original text should be shown and not the placeholder.

Actual behavior:

grafik

Server Setup Information:

Client Setup Information

Chocola04 commented 9 months ago

Hey @robinreckmann i would like to take up this issue, Will you please give a bit more information about how can i reproduce it and you are saying if the message contains any username (like @xyz) it is showing placeholders after translation right?. Would you please check if it is giving the same issue for google translate services. Thankyou

robinreckmann commented 9 months ago

Hey @robinreckmann i would like to take up this issue, Will you please give a bit more information about how can i reproduce it and you are saying if the message contains any username (like @xyz) it is showing placeholders after translation right? Thankyou

Hi @Chocola04,

you can reproduce it by setting up a Microsoft Azure account and create a global resource group for the translator which can then be used to obtain an Ocp-Apim subscription key from the "Keys and Endpoint" section within the previously created resource: https://azure.microsoft.com/en-us/free/ai-services

The key is then used in Rocket.Chat under "Workspace" => "Settings" => "Message", where you need to enable Auto-Translate first, then select the Service Provider "Microsoft", and finally enter the Ocp-Apim key under "Microsoft" => "Ocp-Apim-Subscription-Key" (it does not matter which one of the two you are using).

The final steps would be to create a room, add some users to it, and then activate Auto-Translate and the Auto Translate language in the room settings for each user: grafik

Sending a message with a username mention - like you said - will then create those placeholders inside the message.

Edit: We were using Google Translate before and it worked without a problem. The issue only occurs when we are using Microsoft Translation.

Chocola04 commented 9 months ago

Hey @robinreckmann so, i figured out why it is not working in the microsoft translator, In the google translator after the message being translated, the translated message is called in detokenize function which replaces the token with the actual text but this function is not called in ms translator so i made the changes as you can see in the image below, but i don't know why it is still not working so please help me where i did wrong Screenshot from 2023-12-12 18-19-17

robinreckmann commented 9 months ago

Hi @Chocola04 sorry for the late response and thank you for your efforts. I think the problem with the code you provided is the return statement inside the outer Object.assign as this is intended to be assigned to the translations variable.

As of now, I have had no time to test it, but something like the following should fix this:

if (request.status === 200 && result.length > 0) {
    // store translation only when the source and target language are different.
    translations = Object.assign(
        {},
        ...targetLanguages.map((language) => ({
            [language]: this.deTokenize(Object.assign({}, message, { msg: result
                .map(
                    (line: { translations: { to: string; text: string }[] }) =>
                        line.translations.find((translation) => translation.to === language)?.text,
                )
                .join('\n')})),
        })),
    );
}