From 1904a795b87886caaea007e7852afb2ce398293a Mon Sep 17 00:00:00 2001 From: Ryan ZHAO <> Date: Mon, 25 Mar 2024 11:26:58 +1100 Subject: [PATCH] WIP: add new strings --- .../ConversationVC+Interaction.swift | 40 +++++++------------ Session/Conversations/ConversationVC.swift | 26 +++++------- .../Message Cells/InfoMessageCell.swift | 2 +- ...isappearingMessagesSettingsViewModel.swift | 2 +- .../ConversationTitleView.swift | 6 +-- .../Translations/en.lproj/Localizable.strings | 22 ++++++---- .../Settings/PrivacySettingsViewModel.swift | 4 +- .../DisappearingMessageConfiguration.swift | 4 +- .../General/Localization.swift | 4 ++ 9 files changed, 51 insertions(+), 59 deletions(-) diff --git a/Session/Conversations/ConversationVC+Interaction.swift b/Session/Conversations/ConversationVC+Interaction.swift index 695a2c23e..4b3184632 100644 --- a/Session/Conversations/ConversationVC+Interaction.swift +++ b/Session/Conversations/ConversationVC+Interaction.swift @@ -900,34 +900,22 @@ extension ConversationVC: let messageDisappearingConfig = cellViewModel.messageDisappearingConfiguration() let expirationTimerString: String = floor(messageDisappearingConfig.durationSeconds).formatted(format: .long) let expirationTypeString: String = (messageDisappearingConfig.type?.localizedName ?? "") - let modalBodyString: String = ( - messageDisappearingConfig.isEnabled ? - String( - format: "FOLLOW_SETTING_EXPLAINATION_TURNING_ON".localized(), - expirationTimerString, - expirationTypeString - ) : - "FOLLOW_SETTING_EXPLAINATION_TURNING_OFF".localized() - ) + let modalBodyString: String = { + if messageDisappearingConfig.isEnabled { + return "disappearingMessagesFollowSettingOn" + .put(key: "time", value: expirationTimerString) + .put(key: "disappearing messages type", value: expirationTypeString) + .localized() + } else { + return "disappearingMessagesFollowSettingOff" + .localized() + } + }() let modalConfirmTitle: String = messageDisappearingConfig.isEnabled ? "set".localized() : "CONFIRM_BUTTON_TITLE".localized() let confirmationModal: ConfirmationModal = ConfirmationModal( info: ConfirmationModal.Info( - title: "FOLLOW_SETTING_TITLE".localized(), - body: .attributedText( - NSAttributedString(string: modalBodyString) - .adding( - attributes: [ .font: UIFont.boldSystemFont(ofSize: Values.smallFontSize) ], - range: (modalBodyString as NSString).range(of: expirationTypeString) - ) - .adding( - attributes: [ .font: UIFont.boldSystemFont(ofSize: Values.smallFontSize) ], - range: (modalBodyString as NSString).range(of: expirationTimerString) - ) - .adding( - attributes: [ .font: UIFont.boldSystemFont(ofSize: Values.smallFontSize) ], - range: (modalBodyString as NSString).range(of: "off".localized().lowercased()) - ) - ), + title: "disappearingMessagesFollowSetting".localized(), + body: .attributedText(modalBodyString.formatted(baseFont: .systemFont(ofSize: Values.smallFontSize))), accessibility: Accessibility(identifier: "Follow setting dialog"), confirmTitle: modalConfirmTitle, confirmAccessibility: Accessibility(identifier: "Set button"), @@ -1429,7 +1417,7 @@ extension ConversationVC: (sentTimestamp - (recentReactionTimestamps.first ?? sentTimestamp)) > (60 * 1000) else { let toastController: ToastController = ToastController( - text: "EMOJI_REACTS_RATE_LIMIT_TOAST".localized(), + text: "emojiReactsCoolDown".localized(), background: .backgroundSecondary ) toastController.presentToastView( diff --git a/Session/Conversations/ConversationVC.swift b/Session/Conversations/ConversationVC.swift index 40cab5c0e..09ad37424 100644 --- a/Session/Conversations/ConversationVC.swift +++ b/Session/Conversations/ConversationVC.swift @@ -744,15 +744,15 @@ final class ConversationVC: BaseVC, SessionUtilRespondingViewController, Convers case (true, _): return "noteToSelfEmpty".localized() case (_, false): - return (threadData.profile?.blocksCommunityMessageRequests == true ? - String( - format: "COMMUNITY_MESSAGE_REQUEST_DISABLED_EMPTY_STATE".localized(), - threadData.displayName - ) : - "conversationsEmpty" - .put(key: "conversationname", value: threadData.displayName) - .localized() - ) + if threadData.profile?.blocksCommunityMessageRequests == true { + return "messageRequestsTurnedOff" + .put(key: "name", value: threadData.displayName) + .localized() + } else { + return "conversationsEmpty" + .put(key: "conversationname", value: threadData.displayName) + .localized() + } default: return "groupNoMessages" .put(key: "groupname", value: threadData.displayName) @@ -803,13 +803,7 @@ final class ConversationVC: BaseVC, SessionUtilRespondingViewController, Convers // Update the empty state let text: String = emptyStateText(for: updatedThreadData) - emptyStateLabel.attributedText = NSAttributedString(string: text) - .adding( - attributes: [.font: UIFont.boldSystemFont(ofSize: Values.verySmallFontSize)], - range: text.range(of: updatedThreadData.displayName) - .map { NSRange($0, in: text) } - .defaulting(to: NSRange(location: 0, length: 0)) - ) + emptyStateLabel.attributedText = text.formatted(in: emptyStateLabel) } if diff --git a/Session/Conversations/Message Cells/InfoMessageCell.swift b/Session/Conversations/Message Cells/InfoMessageCell.swift index 8eb958c2d..e1c7b61b5 100644 --- a/Session/Conversations/Message Cells/InfoMessageCell.swift +++ b/Session/Conversations/Message Cells/InfoMessageCell.swift @@ -124,7 +124,7 @@ final class InfoMessageCell: MessageCell { if cellViewModel.canDoFollowingSetting() { self.actionLabel.isHidden = false - self.actionLabel.text = "FOLLOW_SETTING_TITLE".localized() + self.actionLabel.text = "disappearingMessagesFollowSetting".localized() } self.label.themeTextColor = (cellViewModel.variant == .infoClosedGroupCurrentUserErrorLeaving) ? .danger : .textSecondary diff --git a/Session/Conversations/Settings/ThreadDisappearingMessagesSettingsViewModel.swift b/Session/Conversations/Settings/ThreadDisappearingMessagesSettingsViewModel.swift index d8ed1486a..6c49c4db4 100644 --- a/Session/Conversations/Settings/ThreadDisappearingMessagesSettingsViewModel.swift +++ b/Session/Conversations/Settings/ThreadDisappearingMessagesSettingsViewModel.swift @@ -92,7 +92,7 @@ class ThreadDisappearingMessagesSettingsViewModel: SessionTableViewModel, Naviga } if threadVariant == .contact && !isNoteToSelf { - return "DISAPPERING_MESSAGES_SUBTITLE_CONTACTS".localized() + return "disappearingMessagesDescription1".localized() } return "disappearingMessagesDisappearAfterSendDescription".localized() diff --git a/Session/Conversations/Views & Modals/ConversationTitleView.swift b/Session/Conversations/Views & Modals/ConversationTitleView.swift index 1748cd809..991c070af 100644 --- a/Session/Conversations/Views & Modals/ConversationTitleView.swift +++ b/Session/Conversations/Views & Modals/ConversationTitleView.swift @@ -208,9 +208,9 @@ final class ConversationTitleView: UIView { case .community: labelInfos.append( SessionLabelCarouselView.LabelInfo( - attributedText: NSAttributedString( - string: "\(userCount) active member\(userCount == 1 ? "" : "s")" - ), + attributedText: "membersActive" + .put(key: "count", value: userCount) + .localizedFormatted(baseFont: .systemFont(ofSize: Values.miniFontSize)), accessibility: nil, // TODO: Add accessibility type: .userCount ) diff --git a/Session/Meta/Translations/en.lproj/Localizable.strings b/Session/Meta/Translations/en.lproj/Localizable.strings index 1c6c2cb42..1e51e6adf 100644 --- a/Session/Meta/Translations/en.lproj/Localizable.strings +++ b/Session/Meta/Translations/en.lproj/Localizable.strings @@ -615,6 +615,20 @@ "resolving" = "Resolving..."; "disappearingMessagesLegacy" = "{name} is using an outdated client. Disappearing messages may not work as expected."; "showLess" = "Show Less"; +"membersActive" = "{count} active members"; +"disappearingMessagesTypeSent" = "sent"; +"disappearingMessagesTypeRead" = "read"; +"messageRequestsTurnedOff" = "{name} has message requests from Community conversations turned off, so you cannot send them a message."; +"messageRequestsCommunities" = "Community Message Requests"; +"messageReqeuestsCommunitiesDescription" = "Allow message requests from Community conversations."; +"emojiReactsCoolDown" = "Slow down! You've sent too many emoji reacts. Try again soon."; +"disappearingMessagesDescription1" = "This setting applies to messages you send in this conversation."; +"disappearingMessagesFollowSetting" = "Follow Setting"; +"disappearingMessagesFollowSettingOn" = "Set your messages to disappear {time} after they have been {disappearing messages type}?"; +"disappearingMessagesFollowSettingOff" = "Messages you send will no longer disappear. Are you sure you want to turn off disappearing messages?"; +"groupInviteVersion" = "Users must have version {version} or higher to receive invitations"; +"blockBlockedUser" = "Blocked {name}"; +"blockUnblockedUser" = "Unblocked {name}"; // NOT IN THE LIST YET "APP_STARTUP_EXIT" = "Exit"; @@ -633,7 +647,6 @@ "GROUP_UPDATE_ERROR_TITLE" = "Couldn't Update Group"; "vc_conversation_voice_message_cancel_message" = "Slide to Cancel"; "MEDIA_GALLERY_MORE_ITEMS_FORMAT" = "+%@"; -"FOLLOW_SETTING_TITLE" = "Follow Setting"; "context_menu_resync" = "Resync"; "context_menu_ban_and_delete_all" = "Ban and Delete All"; "DISAPPEARING_MESSAGES_AUTO_DELETES_COUNT_DOWN" = "Auto-deletes in %@"; @@ -647,12 +660,10 @@ "vc_conversation_settings_notify_for_mentions_only_title" = "Notify for Mentions Only"; "vc_conversation_settings_notify_for_mentions_only_explanation" = "When enabled, you'll only be notified for messages mentioning you."; "CONVERSATION_SETTINGS_BLOCK_THIS_USER" = "Block This User"; -"DISAPPERING_MESSAGES_SUBTITLE_CONTACTS" = "This setting applies to messages you send in this conversation."; "DISAPPEARING_MESSAGES_TYPE_LEGACY_TITLE" = "Legacy"; // TODO: Delete "DISAPPEARING_MESSAGES_TYPE_LEGACY_DESCRIPTION" = "Original version of disappearing messages."; // TODO: Delete "FAILED_TO_STORE_OUTGOING_MESSAGE" = "An error occurred when trying to store the outgoing message for sending, you may need to restart the app before you can send messages."; "TXT_BLOCK_USER_TITLE" = "Block User"; -"COMMUNITY_MESSAGE_REQUEST_DISABLED_EMPTY_STATE" = "%@ has message requests from Community conversations turned off, so you cannot send them a message."; "CONVERSATION_SEARCH_ONE_RESULT" = "1 match"; "DM_ERROR_DIRECT_BLINDED_ID" = "You can only send messages to Blinded IDs from within a Community"; "DM_ERROR_INVALID" = "Please check the Session ID or ONS name and try again"; @@ -708,8 +719,6 @@ "CONVERSATION_SETTINGS_AUDIO_MESSAGES_AUTOPLAY_TITLE" = "Autoplay Audio Messages"; "CONVERSATION_SETTINGS_AUDIO_MESSAGES_AUTOPLAY_DESCRIPTION" = "Autoplay consecutive audio messages."; "SETTINGS_AUDIO_DEFAULT_TONE_LABEL_FORMAT" = "%@ (default)"; -"PRIVACY_SCREEN_MESSAGE_REQUESTS_COMMUNITY_TITLE" = "Community Message Requests"; -"PRIVACY_SCREEN_MESSAGE_REQUESTS_COMMUNITY_DESCRIPTION" = "Allow message requests from Community conversations."; "qrCode" = "QR Code"; "vc_qr_code_view_scan_qr_code_explanation" = "Scan someone's QR code to start a conversation with them"; // TODO: Delete "invalid_session_id" = "Invalid Session ID"; // TODO: Delete @@ -738,10 +747,7 @@ "GIPHY_PERMISSION_TITLE" = "Search GIFs?"; "GIPHY_PERMISSION_MESSAGE" = "Session will connect to Giphy to provide search results. You will not have full metadata protection when sending GIFs."; "ATTACHMENT_PICKER_DOCUMENTS_FAILED_ALERT_TITLE" = "Failed to choose document."; -"FOLLOW_SETTING_EXPLAINATION_TURNING_ON" = "Set your messages to disappear %@ after they have been %@?"; -"FOLLOW_SETTING_EXPLAINATION_TURNING_OFF" = "Messages you send will no longer disappear. Are you sure you want to turn off disappearing messages?"; "CONFIRM_BUTTON_TITLE" = "Confirm"; -"EMOJI_REACTS_RATE_LIMIT_TOAST" = "Slow down! You've sent too many emoji reacts. Try again soon."; "MESSAGE_DELIVERY_FAILED_SYNC_TITLE" = "Failed to sync message to your other devices"; "MESSAGE_DELIVERY_FAILED_TITLE" = "Failed to send message"; "delete_message_for_me_and_my_devices" = "Delete from all of my devices"; diff --git a/Session/Settings/PrivacySettingsViewModel.swift b/Session/Settings/PrivacySettingsViewModel.swift index 9ea2c17aa..73c0a9e4a 100644 --- a/Session/Settings/PrivacySettingsViewModel.swift +++ b/Session/Settings/PrivacySettingsViewModel.swift @@ -145,8 +145,8 @@ class PrivacySettingsViewModel: SessionTableViewModel, NavigationItemSource, Nav elements: [ SessionCell.Info( id: .communityMessageRequests, - title: "PRIVACY_SCREEN_MESSAGE_REQUESTS_COMMUNITY_TITLE".localized(), - subtitle: "PRIVACY_SCREEN_MESSAGE_REQUESTS_COMMUNITY_DESCRIPTION".localized(), + title: "messageRequestsCommunities".localized(), + subtitle: "messageReqeuestsCommunitiesDescription".localized(), rightAccessory: .toggle( .boolValue( key: .checkForCommunityMessageRequests, diff --git a/SessionMessagingKit/Database/Models/DisappearingMessageConfiguration.swift b/SessionMessagingKit/Database/Models/DisappearingMessageConfiguration.swift index af0626807..601779900 100644 --- a/SessionMessagingKit/Database/Models/DisappearingMessageConfiguration.swift +++ b/SessionMessagingKit/Database/Models/DisappearingMessageConfiguration.swift @@ -46,9 +46,9 @@ public struct DisappearingMessagesConfiguration: Codable, Identifiable, Equatabl case .unknown: return "" case .disappearAfterRead: - return "read".localized().lowercased() + return "disappearingMessagesTypeRead".localized() case .disappearAfterSend: - return "disappearingMessagesSent".localized().lowercased() + return "disappearingMessagesTypeSent".localized() } } diff --git a/SessionUtilitiesKit/General/Localization.swift b/SessionUtilitiesKit/General/Localization.swift index 47890a1db..4f00a1351 100644 --- a/SessionUtilitiesKit/General/Localization.swift +++ b/SessionUtilitiesKit/General/Localization.swift @@ -269,4 +269,8 @@ public extension String { func formatted(in view: FontAccessible) -> NSAttributedString { return NSAttributedString(stringWithHTMLTags: self, font: (view.fontValue ?? .systemFont(ofSize: 14))) } + + func formatted(baseFont: UIFont) -> NSAttributedString { + return NSAttributedString(stringWithHTMLTags: self, font: baseFont) + } }