[FIX] Auto-translate feature wasn't working (#4678)

This commit is contained in:
Reinaldo Neto 2022-11-11 16:51:57 -03:00 committed by GitHub
parent 82c922fa4d
commit b0ea5e31f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 6 deletions

View File

@ -45,6 +45,7 @@ interface IMarkdownProps {
testID?: string; testID?: string;
style?: StyleProp<TextStyle>[]; style?: StyleProp<TextStyle>[];
onLinkPress?: TOnLinkPress; onLinkPress?: TOnLinkPress;
isTranslated?: boolean;
} }
type TLiteral = { type TLiteral = {
@ -93,10 +94,8 @@ class Markdown extends PureComponent<IMarkdownProps, any> {
constructor(props: IMarkdownProps) { constructor(props: IMarkdownProps) {
super(props); super(props);
if (!this.isNewMarkdown) {
this.renderer = this.createRenderer(); this.renderer = this.createRenderer();
} }
}
createRenderer = () => createRenderer = () =>
new Renderer({ new Renderer({
@ -310,13 +309,24 @@ class Markdown extends PureComponent<IMarkdownProps, any> {
}; };
render() { render() {
const { msg, md, mentions, channels, navToRoomInfo, useRealName, username = '', getCustomEmoji, onLinkPress } = this.props; const {
msg,
md,
mentions,
channels,
navToRoomInfo,
useRealName,
username = '',
getCustomEmoji,
onLinkPress,
isTranslated
} = this.props;
if (!msg) { if (!msg) {
return null; return null;
} }
if (this.isNewMarkdown) { if (this.isNewMarkdown && !isTranslated) {
return ( return (
<NewMarkdown <NewMarkdown
username={username} username={username}

View File

@ -64,6 +64,7 @@ const Content = React.memo(
useRealName={props.useRealName} useRealName={props.useRealName}
theme={theme} theme={theme}
onLinkPress={onLinkPress} onLinkPress={onLinkPress}
isTranslated={props.isTranslated}
/> />
); );
} }

View File

@ -376,10 +376,13 @@ class MessageContainer extends React.Component<IMessageContainerProps, IMessageC
} = item; } = item;
let message = msg; let message = msg;
let isTranslated = false;
// "autoTranslateRoom" and "autoTranslateLanguage" are properties from the subscription // "autoTranslateRoom" and "autoTranslateLanguage" are properties from the subscription
// "autoTranslateMessage" is a toggle between "View Original" and "Translate" state // "autoTranslateMessage" is a toggle between "View Original" and "Translate" state
if (autoTranslateRoom && autoTranslateMessage && autoTranslateLanguage) { if (autoTranslateRoom && autoTranslateMessage && autoTranslateLanguage) {
message = getMessageTranslation(item, autoTranslateLanguage) || message; const messageTranslated = getMessageTranslation(item, autoTranslateLanguage);
isTranslated = !!messageTranslated;
message = messageTranslated || message;
} }
return ( return (
@ -455,6 +458,7 @@ class MessageContainer extends React.Component<IMessageContainerProps, IMessageC
blockAction={blockAction} blockAction={blockAction}
highlighted={highlighted} highlighted={highlighted}
comment={comment} comment={comment}
isTranslated={isTranslated}
/> />
</MessageContext.Provider> </MessageContext.Provider>
); );

View File

@ -63,6 +63,7 @@ export interface IMessageContent {
comment?: string; comment?: string;
hasError: boolean; hasError: boolean;
isHeader: boolean; isHeader: boolean;
isTranslated: boolean;
} }
export interface IMessageEmoji { export interface IMessageEmoji {