Skip to content

Commit

Permalink
Add call localization
Browse files Browse the repository at this point in the history
  • Loading branch information
Isaac committed Dec 29, 2023
1 parent d88c78d commit 3fb85da
Show file tree
Hide file tree
Showing 10 changed files with 197 additions and 41 deletions.
11 changes: 11 additions & 0 deletions Telegram/Telegram-iOS/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -4418,6 +4418,7 @@ Sorry for the inconvenience.";

"Call.Mute" = "mute";
"Call.Camera" = "camera";
"Call.Video" = "video";
"Call.Flip" = "flip";
"Call.End" = "end";
"Call.Speaker" = "speaker";
Expand Down Expand Up @@ -5646,6 +5647,7 @@ Sorry for the inconvenience.";
"Call.CameraConfirmationText" = "Switch to video call?";
"Call.CameraConfirmationConfirm" = "Switch";

"Call.YourCameraOff" = "Your camera is off";
"Call.YourMicrophoneOff" = "Your microphone is off";
"Call.MicrophoneOff" = "%@'s microphone is off";
"Call.CameraOff" = "%@'s camera is off";
Expand Down Expand Up @@ -10867,3 +10869,12 @@ Sorry for the inconvenience.";
"Chat.PlayOnceMesasgeClose" = "Close";
"Chat.PlayOnceMesasgeCloseAndDelete" = "Close and Delete";
"Chat.PlayOnceMesasge.DisableScreenCapture" = "Sorry, you can't play this message while screen recording is active.";

"Call.EncryptedAlertTitle" = "This call is end-to-end encrypted";
"Call.EncryptedAlertText" = "If the emoji on %@'s screen are the same, this call is 100% secure.";
"Call.EncryptionKeyTooltip" = "Encryption key of this call";
"Call.StatusBusy" = "Line Busy";
"Call.StatusDeclined" = "Call Declined";
"Call.StatusFailed" = "Call Failed";
"Call.StatusEnded" = "Call Ended";
"Call.StatusMissed" = "Call Missed";
2 changes: 1 addition & 1 deletion Tests/CallUITest/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ swift_library(
deps = [
"//submodules/Display",
"//submodules/MetalEngine",
"//submodules/TelegramPresentationData",
"//submodules/TelegramUI/Components/Calls/CallScreen",
],
)
Expand Down Expand Up @@ -188,5 +189,4 @@ xcodeproj(
},
},
default_xcode_configuration = "Debug"

)
2 changes: 2 additions & 0 deletions Tests/CallUITest/Sources/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import MetalEngine
import Display
import CallScreen
import ComponentFlow
import TelegramPresentationData

private extension UIScreen {
private static let cornerRadiusKey: String = {
Expand All @@ -24,6 +25,7 @@ private extension UIScreen {
public final class ViewController: UIViewController {
private var callScreenView: PrivateCallScreen?
private var callState: PrivateCallScreen.State = PrivateCallScreen.State(
strings: defaultPresentationStrings,
lifecycleState: .connecting,
name: "Emma Walters",
shortName: "Emma",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ final class CallControllerNodeV2: ViewControllerTracingNode, CallControllerNodeP
}

self.callScreenState = PrivateCallScreen.State(
strings: presentationData.strings,
lifecycleState: .connecting,
name: " ",
shortName: " ",
Expand Down
1 change: 1 addition & 0 deletions submodules/TelegramUI/Components/Calls/CallScreen/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ swift_library(
"//submodules/TelegramUI/Components/AnimatedTextComponent",
"//submodules/AppBundle",
"//submodules/UIKitRuntimeUtils",
"//submodules/TelegramPresentationData",
],
visibility = [
"//visibility:public",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "Snow.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,39 @@ import UIKit
import Display

final class BackButtonView: HighlightableButton {
private struct Params: Equatable {
var text: String

init(text: String) {
self.text = text
}
}

private struct Layout: Equatable {
var params: Params
var size: CGSize

init(params: Params, size: CGSize) {
self.params = params
self.size = size
}
}

private let iconView: UIImageView
private let textView: TextView

let size: CGSize
private var currentLayout: Layout?

var pressAction: (() -> Void)?

init(text: String) {
override init(frame: CGRect) {
self.iconView = UIImageView(image: NavigationBar.backArrowImage(color: .white))
self.iconView.isUserInteractionEnabled = false

self.textView = TextView()
self.textView.isUserInteractionEnabled = false

let spacing: CGFloat = 8.0

var iconSize: CGSize = self.iconView.image?.size ?? CGSize(width: 2.0, height: 2.0)
let iconScaleFactor: CGFloat = 0.9
iconSize.width = floor(iconSize.width * iconScaleFactor)
iconSize.height = floor(iconSize.height * iconScaleFactor)

let textSize = self.textView.update(string: text, fontSize: 17.0, fontWeight: UIFont.Weight.regular.rawValue, color: .white, constrainedWidth: 100.0, transition: .immediate)
self.size = CGSize(width: iconSize.width + spacing + textSize.width, height: textSize.height)

self.iconView.frame = CGRect(origin: CGPoint(x: 0.0, y: floorToScreenPixels((self.size.height - iconSize.height) * 0.5)), size: iconSize)
self.textView.frame = CGRect(origin: CGPoint(x: iconSize.width + spacing, y: floorToScreenPixels((self.size.height - textSize.height) * 0.5)), size: textSize)

super.init(frame: CGRect())
super.init(frame: frame)

self.addSubview(self.iconView)
self.addSubview(self.textView)
Expand All @@ -53,4 +58,31 @@ final class BackButtonView: HighlightableButton {
return nil
}
}

func update(text: String) -> CGSize {
let params = Params(text: text)
if let currentLayout = self.currentLayout, currentLayout.params == params {
return currentLayout.size
}
let size = self.update(params: params)
self.currentLayout = Layout(params: params, size: size)
return size
}

private func update(params: Params) -> CGSize {
let spacing: CGFloat = 8.0

var iconSize: CGSize = self.iconView.image?.size ?? CGSize(width: 2.0, height: 2.0)
let iconScaleFactor: CGFloat = 0.9
iconSize.width = floor(iconSize.width * iconScaleFactor)
iconSize.height = floor(iconSize.height * iconScaleFactor)

let textSize = self.textView.update(string: params.text, fontSize: 17.0, fontWeight: UIFont.Weight.regular.rawValue, color: .white, constrainedWidth: 100.0, transition: .immediate)
let size = CGSize(width: iconSize.width + spacing + textSize.width, height: textSize.height)

self.iconView.frame = CGRect(origin: CGPoint(x: 0.0, y: floorToScreenPixels((size.height - iconSize.height) * 0.5)), size: iconSize)
self.textView.frame = CGRect(origin: CGPoint(x: iconSize.width + spacing, y: floorToScreenPixels((size.height - textSize.height) * 0.5)), size: textSize)

return size
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import UIKit
import Display
import ComponentFlow
import AppBundle
import TelegramPresentationData

final class ButtonGroupView: OverlayMaskContainerView {
final class Button {
Expand Down Expand Up @@ -85,7 +86,7 @@ final class ButtonGroupView: OverlayMaskContainerView {
return result
}

func update(size: CGSize, insets: UIEdgeInsets, minWidth: CGFloat, controlsHidden: Bool, displayClose: Bool, buttons: [Button], notices: [Notice], transition: Transition) -> CGFloat {
func update(size: CGSize, insets: UIEdgeInsets, minWidth: CGFloat, controlsHidden: Bool, displayClose: Bool, strings: PresentationStrings, buttons: [Button], notices: [Notice], transition: Transition) -> CGFloat {
self.buttons = buttons

let buttonSize: CGFloat = 56.0
Expand Down Expand Up @@ -190,7 +191,7 @@ final class ButtonGroupView: OverlayMaskContainerView {
}
}
let closeButtonSize = CGSize(width: minWidth, height: buttonSize)
closeButtonView.update(text: "Close", size: closeButtonSize, transition: closeButtonTransition)
closeButtonView.update(text: strings.Common_Close, size: closeButtonSize, transition: closeButtonTransition)
closeButtonTransition.setFrame(view: closeButtonView, frame: CGRect(origin: CGPoint(x: floor((size.width - closeButtonSize.width) * 0.5), y: buttonY), size: closeButtonSize))

if animateIn && !transition.animation.isImmediate {
Expand Down Expand Up @@ -218,9 +219,9 @@ final class ButtonGroupView: OverlayMaskContainerView {
case let .speaker(audioOutput):
switch audioOutput {
case .internalSpeaker, .speaker:
title = "speaker"
title = strings.Call_Speaker
default:
title = "audio"
title = strings.Call_Audio
}

switch audioOutput {
Expand All @@ -247,19 +248,19 @@ final class ButtonGroupView: OverlayMaskContainerView {
isActive = true
}
case .flipCamera:
title = "flip"
title = strings.Call_Flip
image = UIImage(bundleImageName: "Call/Flip")
isActive = false
case let .video(isActiveValue):
title = "video"
title = strings.Call_Video
image = UIImage(bundleImageName: "Call/Video")
isActive = isActiveValue
case let .microphone(isActiveValue):
title = "mute"
title = strings.Call_Mute
image = UIImage(bundleImageName: "Call/Mute")
isActive = isActiveValue
case .end:
title = "end"
title = strings.Call_End
image = UIImage(bundleImageName: "Call/End")
isActive = false
isDestructive = true
Expand Down
Loading

0 comments on commit 3fb85da

Please sign in to comment.