diff --git a/Session/Meta/Translations/InfoPlist.xcstrings b/Session/Meta/Translations/InfoPlist.xcstrings index d784d71c7..4bda155f5 100644 --- a/Session/Meta/Translations/InfoPlist.xcstrings +++ b/Session/Meta/Translations/InfoPlist.xcstrings @@ -1,129 +1 @@ -{ - "sourceLanguage" : "en", - "strings" : { - "CFBundleDisplayName" : { - "comment" : "Bundle display name", - "extractionState" : "extracted_with_value", - "localizations" : { - "en" : { - "stringUnit" : { - "state" : "new", - "value" : "Session" - } - } - } - }, - "CFBundleGetInfoString" : { - "comment" : "Get Info string", - "extractionState" : "extracted_with_value", - "localizations" : { - "en" : { - "stringUnit" : { - "state" : "new", - "value" : "" - } - } - } - }, - "CFBundleName" : { - "comment" : "Bundle name", - "extractionState" : "extracted_with_value", - "localizations" : { - "en" : { - "stringUnit" : { - "state" : "new", - "value" : "Session" - } - } - } - }, - "New Message" : { - - }, - "NSAppleMusicUsageDescription" : { - "extractionState" : "manual", - "localizations" : { - "en" : { - "stringUnit" : { - "state" : "translated", - "value" : "Session needs to use Apple Music to play media attachments." - } - }, - "zh_CN" : { - "stringUnit" : { - "state" : "translated", - "value" : "Session需要Apple Music的访问权限用以播放媒体附件。" - } - } - } - }, - "NSCameraUsageDescription" : { - "extractionState" : "manual", - "localizations" : { - "en" : { - "stringUnit" : { - "state" : "translated", - "value" : "Session needs camera access to take pictures and scan QR codes." - } - } - } - }, - "NSFaceIDUsageDescription" : { - "extractionState" : "manual", - "localizations" : { - "en" : { - "stringUnit" : { - "state" : "translated", - "value" : "Session's Screen Lock feature uses Face ID." - } - } - } - }, - "NSHumanReadableCopyright" : { - "comment" : "Copyright (human-readable)", - "extractionState" : "extracted_with_value", - "localizations" : { - "en" : { - "stringUnit" : { - "state" : "new", - "value" : "com.loki-project.loki-messenger" - } - } - } - }, - "NSMicrophoneUsageDescription" : { - "extractionState" : "manual", - "localizations" : { - "en" : { - "stringUnit" : { - "state" : "translated", - "value" : "Session needs access to your microphone for calls and to send to audio messages." - } - } - } - }, - "NSPhotoLibraryAddUsageDescription" : { - "extractionState" : "manual", - "localizations" : { - "en" : { - "stringUnit" : { - "state" : "translated", - "value" : "Session needs access to your library to save photos." - } - } - } - }, - "NSPhotoLibraryUsageDescription" : { - "extractionState" : "manual", - "localizations" : { - "en" : { - "stringUnit" : { - "state" : "translated", - "value" : "Session needs access to your library to update your avatar and send photos." - } - } - } - } - }, - "version" : "1.0" -} \ No newline at end of file +{"sourceLanguage":"en","version":"1.0","strings":{"NSAppleMusicUsageDescription":{"localizations":{"zh_CN":{"stringUnit":{"state":"translated","value":"Session需要Apple Music的访问权限用以播放媒体附件。"}},"en":{"stringUnit":{"state":"translated","value":"Session needs to use Apple Music to play media attachments."}}},"extractionState":"manual"},"NSHumanReadableCopyright":{"comment":"Copyright (human-readable)","localizations":{"en":{"stringUnit":{"state":"new","value":"com.loki-project.loki-messenger"}}},"extractionState":"extracted_with_value"},"New Message":{},"NSPhotoLibraryUsageDescription":{"localizations":{"en":{"stringUnit":{"state":"translated","value":"Session needs access to your library to update your avatar and send photos."}}},"extractionState":"manual"},"NSFaceIDUsageDescription":{"localizations":{"en":{"stringUnit":{"state":"translated","value":"Session's Screen Lock feature uses Face ID."}}},"extractionState":"manual"},"CFBundleName":{"comment":"Bundle name","localizations":{"en":{"stringUnit":{"state":"new","value":"Session"}}},"extractionState":"extracted_with_value"},"CFBundleDisplayName":{"comment":"Bundle display name","localizations":{"en":{"stringUnit":{"state":"new","value":"Session"}}},"extractionState":"extracted_with_value"},"NSPhotoLibraryAddUsageDescription":{"extractionState":"manual","localizations":{"en":{"stringUnit":{"state":"translated","value":"Session needs access to your library to save photos."}}}},"NSCameraUsageDescription":{"localizations":{"en":{"stringUnit":{"state":"translated","value":"Session needs camera access to take pictures and scan QR codes."}}},"extractionState":"manual"},"CFBundleGetInfoString":{"comment":"Get Info string","localizations":{"en":{"stringUnit":{"state":"new","value":""}}},"extractionState":"extracted_with_value"},"NSMicrophoneUsageDescription":{"extractionState":"manual","localizations":{"en":{"stringUnit":{"state":"translated","value":"Session needs access to your microphone for calls and to send to audio messages."}}}}}} \ No newline at end of file diff --git a/Session/Meta/Translations/en.lproj/Localizable.strings b/Session/Meta/Translations/en.lproj/Localizable.strings index ec3dcc517..975e76fe4 100644 --- a/Session/Meta/Translations/en.lproj/Localizable.strings +++ b/Session/Meta/Translations/en.lproj/Localizable.strings @@ -715,20 +715,6 @@ "TXT_BLOCK_USER_TITLE" = "Block User"; "DM_ERROR_DIRECT_BLINDED_ID" = "You can only send messages to Blinded IDs from within a Community"; "LOADING_CONVERSATIONS" = "Loading Conversations..."; -"TIME_AMOUNT_SECONDS" = "%@ seconds"; -"TIME_AMOUNT_SINGLE_MINUTE" = "%@ minute"; -"TIME_AMOUNT_MINUTES" = "%@ minutes"; -"TIME_AMOUNT_SINGLE_HOUR" = "%@ hour"; -"TIME_AMOUNT_HOURS" = "%@ hours"; -"TIME_AMOUNT_SINGLE_DAY" = "%@ day"; -"TIME_AMOUNT_DAYS" = "%@ days"; -"TIME_AMOUNT_SINGLE_WEEK" = "%@ week"; -"TIME_AMOUNT_WEEKS" = "%@ weeks"; -"TIME_AMOUNT_WEEKS_SHORT_FORMAT" = "%@w"; -"TIME_AMOUNT_DAYS_SHORT_FORMAT" = "%@d"; -"TIME_AMOUNT_HOURS_SHORT_FORMAT" = "%@h"; -"TIME_AMOUNT_MINUTES_SHORT_FORMAT" = "%@m"; -"TIME_AMOUNT_SECONDS_SHORT_FORMAT" = "%@s"; "ATTACHMENT_ERROR_MISSING_DATA" = "Attachment is empty."; "ATTACHMENT_ERROR_COULD_NOT_PARSE_IMAGE" = "Unable to parse image."; "ATTACHMENT_ERROR_COULD_NOT_CONVERT_TO_MP4" = "Unable to process video."; diff --git a/SessionUtilitiesKit/General/String+Utilities.swift b/SessionUtilitiesKit/General/String+Utilities.swift index bde048169..6b6897a3d 100644 --- a/SessionUtilitiesKit/General/String+Utilities.swift +++ b/SessionUtilitiesKit/General/String+Utilities.swift @@ -88,239 +88,43 @@ extension String.StringInterpolation { public extension String { static func formattedDuration(_ duration: TimeInterval, format: TimeInterval.DurationFormat = .short) -> String { - let secondsPerMinute: TimeInterval = 60 - let secondsPerHour: TimeInterval = (secondsPerMinute * 60) - let secondsPerDay: TimeInterval = (secondsPerHour * 24) - let secondsPerWeek: TimeInterval = (secondsPerDay * 7) + var dateComponentsFormatter = DateComponentsFormatter() + dateComponentsFormatter.allowedUnits = [.weekOfMonth, .day, .hour, .minute, .second] + var calendar = Calendar.current switch format { case .videoDuration: - let seconds: Int = Int(duration.truncatingRemainder(dividingBy: 60)) - let minutes: Int = Int((duration / 60).truncatingRemainder(dividingBy: 60)) - let hours: Int = Int(duration / 3600) - - guard hours > 0 else { return String(format: "%02ld:%02ld", minutes, seconds) } - - return String(format: "%ld:%02ld:%02ld", hours, minutes, seconds) + guard duration < 3600 else { fallthrough } + dateComponentsFormatter.maximumUnitCount = 2 + dateComponentsFormatter.unitsStyle = .positional + dateComponentsFormatter.zeroFormattingBehavior = .pad + return dateComponentsFormatter.string(from: duration) ?? "" case .hoursMinutesSeconds: - let seconds: Int = Int(duration.truncatingRemainder(dividingBy: 60)) - let minutes: Int = Int((duration / 60).truncatingRemainder(dividingBy: 60)) - let hours: Int = Int(duration / 3600) - - guard hours > 0 else { return String(format: "%ld:%02ld", minutes, seconds) } - - return String(format: "%ld:%02ld:%02ld", hours, minutes, seconds) + dateComponentsFormatter.maximumUnitCount = 3 + dateComponentsFormatter.unitsStyle = .positional + dateComponentsFormatter.zeroFormattingBehavior = .dropLeading + return dateComponentsFormatter.string(from: duration) ?? "" - case .short: - switch duration { - case 0..