From 8fe15da84aef84e8bac9acc69f9ce550f59987ff Mon Sep 17 00:00:00 2001 From: Ryan Miller Date: Thu, 28 Mar 2024 14:22:14 +1100 Subject: [PATCH] feat: change localized strings in ReactionPopup and refactor logic for string selection --- .../message/reactions/ReactionPopup.tsx | 59 +++++++++++-------- 1 file changed, 33 insertions(+), 26 deletions(-) diff --git a/ts/components/conversation/message/reactions/ReactionPopup.tsx b/ts/components/conversation/message/reactions/ReactionPopup.tsx index cefd352cf..4496a6383 100644 --- a/ts/components/conversation/message/reactions/ReactionPopup.tsx +++ b/ts/components/conversation/message/reactions/ReactionPopup.tsx @@ -4,6 +4,7 @@ import styled from 'styled-components'; import { Data } from '../../../../data/data'; import { PubKey } from '../../../../session/types/PubKey'; import { isDarkTheme } from '../../../../state/selectors/theme'; +import { LocalizerToken } from '../../../../types/Localizer'; import { nativeEmojiData } from '../../../../util/emoji'; import { findAndFormatContact } from '../../../../models/message'; @@ -87,7 +88,7 @@ const generateContactsString = async ( }); if (meIndex >= 0) { results.splice(meIndex, 1); - results = [window.i18n('you'), ...results]; + results = [window.i18n('onionRoutingPathYou'), ...results]; } if (results && results.length > 0) { return results; @@ -104,33 +105,39 @@ const Contacts = (contacts: Array, count: number) => { } const reactors = contacts.length; - if (reactors === 1 || reactors === 2 || reactors === 3) { - return ( - - {window.i18n( - reactors === 1 - ? 'reactionPopupOne' - : reactors === 2 - ? 'reactionPopupTwo' - : 'reactionPopupThree', - contacts - )}{' '} - {window.i18n('reactionPopup')} - - ); + + let reactionPopupKey: LocalizerToken; + switch (reactors) { + case 1: + reactionPopupKey = 'reactionPopupOne'; + break; + case 2: + reactionPopupKey = 'reactionPopupTwo'; + break; + case 3: + reactionPopupKey = 'reactionPopupThree'; + break; + default: + reactionPopupKey = 'reactionPopupMany'; } - if (reactors > 3) { - return ( - - {window.i18n('reactionPopupMany', [contacts[0], contacts[1], contacts[3]])}{' '} + + return ( + + {window.i18n(reactionPopupKey, { + name: contacts[0], + name2: contacts[1], + name3: contacts[2], + })}{' '} + {reactors > 3 ? ( - {window.i18n(reactors === 4 ? 'otherSingular' : 'otherPlural', [`${count - 3}`])} - {' '} - {window.i18n('reactionPopup')} - - ); - } - return null; + {window.i18n(reactors === 4 ? 'otherSingular' : 'otherPlural', { + number: `${count - 3}`, + })} + + ) : null} + {window.i18n('reactionPopup')} + + ); }; type Props = {