Skip to content

Commit ef0308b

Browse files
fix inconsistency and translations
1 parent 27efcb3 commit ef0308b

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

apps/meteor/client/components/message/hooks/useNormalizedMessage.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
isFileAudioAttachment,
77
isFileVideoAttachment,
88
isQuoteAttachment,
9+
isTranslatedMessage,
910
} from '@rocket.chat/core-typings';
1011
import type { Options } from '@rocket.chat/message-parser';
1112
import { useMemo } from 'react';
@@ -81,12 +82,17 @@ export const useNormalizedMessage = <TMessage extends IMessage>(
8182
};
8283

8384
if (message.msg && message.msg.length > maxMarkdownParseLength) {
85+
const { showAutoTranslate, autoTranslateLanguage } = autoTranslateOptions;
86+
const translations = autoTranslateLanguage && isTranslatedMessage(message) && message.translations;
87+
const translated = showAutoTranslate(message);
88+
const text = (translated && translations && translations[autoTranslateLanguage]) || message.msg;
89+
8490
return {
8591
...message,
8692
md: [
8793
{
8894
type: 'PARAGRAPH',
89-
value: [{ type: 'PLAIN_TEXT', value: message.msg }],
95+
value: [{ type: 'PLAIN_TEXT', value: text }],
9096
},
9197
],
9298
attachments: message.attachments

apps/meteor/client/views/room/MessageList/hooks/useMessageBody.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { IMessage } from '@rocket.chat/core-typings';
1+
import { isTranslatedMessage, type IMessage } from '@rocket.chat/core-typings';
22
import type { Options, Root } from '@rocket.chat/message-parser';
33
import { useMemo } from 'react';
44

@@ -16,7 +16,17 @@ export const useMessageBody = (message: IMessage | undefined, maxMarkdownParseLe
1616
}
1717

1818
if (message.msg && message.msg.length > maxMarkdownParseLength) {
19-
return message.msg;
19+
const { showAutoTranslate, autoTranslateLanguage } = autoTranslateOptions;
20+
const translations = autoTranslateLanguage && isTranslatedMessage(message) && message.translations;
21+
const translated = showAutoTranslate(message);
22+
const text = (translated && translations && translations[autoTranslateLanguage]) || message.msg;
23+
24+
return [
25+
{
26+
type: 'PARAGRAPH',
27+
value: [{ type: 'PLAIN_TEXT', value: text }],
28+
},
29+
];
2030
}
2131

2232
if (message.md) {

0 commit comments

Comments
 (0)