From c1c8dd203b2a7199240422448963db36a04b3a05 Mon Sep 17 00:00:00 2001 From: Ruzanna Date: Fri, 11 Nov 2022 17:33:07 +0400 Subject: [PATCH 01/14] Make changes for iOS localization --- .../Document/DocumentCameraController.swift | 51 ++++++++++++++++--- .../AcuantCamera/View/CameraTextView.swift | 4 +- .../FaceCaptureController.swift | 46 +++++++++++++++-- 3 files changed, 90 insertions(+), 11 deletions(-) diff --git a/AcuantCamera/AcuantCamera/Camera/Document/DocumentCameraController.swift b/AcuantCamera/AcuantCamera/Camera/Document/DocumentCameraController.swift index 7f67015..18c31a0 100644 --- a/AcuantCamera/AcuantCamera/Camera/Document/DocumentCameraController.swift +++ b/AcuantCamera/AcuantCamera/Camera/Document/DocumentCameraController.swift @@ -46,6 +46,8 @@ import AcuantCommon private var currentStateCount = 0 private var isNavigationHidden = false + + public var currentLangCode: String? public class func getCameraController(delegate: CameraCaptureDelegate, cameraOptions: CameraOptions) -> DocumentCameraController { let c = DocumentCameraController() @@ -69,6 +71,10 @@ import AcuantCommon let gestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(touchAction(_:))) self.view.addGestureRecognizer(gestureRecognizer) + + if let currentLanguageCode = currentLangCode { + LanguageManager.shared.langCode = currentLanguageCode + } } @objc internal func touchAction(_ sender: UITapGestureRecognizer) { @@ -134,7 +140,7 @@ import AcuantCommon queue: .main) { [weak self] _ in guard let self = self, self.alertView == nil else { return } - self.messageLayer.string = NSLocalizedString("acuant_camera_paused", comment: "") + self.messageLayer.string = "acuant_camera_paused".localized let alertView = CameraAlertView(frame: self.view.bounds) self.view.addSubview(alertView) self.view.bringSubviewToFront(alertView) @@ -149,7 +155,7 @@ import AcuantCommon self.alertView?.removeFromSuperview() self.alertView = nil if !self.autoCapture { - self.messageLayer.string = NSLocalizedString("acuant_camera_manual_capture", comment: "") + self.messageLayer.string = "acuant_camera_manual_capture".localized } } } @@ -347,7 +353,7 @@ import AcuantCommon } if let localString = localString { - self.cancelCapture(state: state, message: NSLocalizedString(localString, comment: "")) + self.cancelCapture(state: state, message: localString.localized) } else { self.setLookFromState(state: state) } @@ -425,7 +431,7 @@ extension DocumentCameraController: DocumentCaptureDelegate { public func readyToCapture() { DispatchQueue.main.async { if self.messageLayer != nil { - self.messageLayer.string = NSLocalizedString("acuant_camera_capturing", comment: "") + self.messageLayer.string = "acuant_camera_capturing".localized if self.autoCapture { self.setLookFromState(state: DocumentCameraController.CameraState.Capture) } else { @@ -476,7 +482,7 @@ extension DocumentCameraController: FrameAnalysisDelegate { self.transitionState(state: CameraState.Hold) if self.isDocumentMoved(points: scaledPoints) { - self.cancelCapture(state: CameraState.Steady, message: NSLocalizedString("acuant_camera_hold_steady", comment: "")) + self.cancelCapture(state: CameraState.Steady, message: "acuant_camera_hold_steady".localized) } else if !self.captured { self.triggerCapture() } @@ -499,9 +505,42 @@ extension DocumentCameraController: AutoCaptureDelegate { self.autoCapture = autoCapture if !autoCapture { DispatchQueue.main.async { - self.messageLayer.string = NSLocalizedString("acuant_camera_manual_capture", comment: "") + self.messageLayer.string = "acuant_camera_manual_capture".localized } } } } + +// MARK: - Custom Localization + +open class LanguageManager { + static let shared = LanguageManager() + + var langCode: String? + private(set) var currentLanguage: String + + private init() { + if let appLanguage = langCode { + currentLanguage = appLanguage + } else { + currentLanguage = Locale.current.languageCode! + } + } + + public static func localizedstring(_ key: String, comment: String = "") -> String { + let bundle = Bundle.main + guard let path = bundle.path(forResource: LanguageManager.shared.currentLanguage, ofType: "lproj"), + let string = Bundle(path: path)?.localizedString(forKey: key, value: "", table: "") else { + return NSLocalizedString(key, comment: comment) + } + return string + } + +} + +extension String { + public var localized: String { + return LanguageManager.localizedstring(self) + } +} diff --git a/AcuantCamera/AcuantCamera/View/CameraTextView.swift b/AcuantCamera/AcuantCamera/View/CameraTextView.swift index 159d48a..396afab 100644 --- a/AcuantCamera/AcuantCamera/View/CameraTextView.swift +++ b/AcuantCamera/AcuantCamera/View/CameraTextView.swift @@ -31,9 +31,9 @@ public class CameraTextView: CATextLayer { super.init() self.opacity = 0.7 if autoCapture { - self.string = NSLocalizedString("acuant_camera_align", comment: "") + self.string = "acuant_camera_align".localized } else { - self.string = NSLocalizedString("acuant_camera_manual_capture", comment: "") + self.string = "acuant_camera_manual_capture".localized } self.alignmentMode = CATextLayerAlignmentMode.center self.cornerRadius = 10 diff --git a/AcuantFaceCapture/AcuantFaceCapture/FaceCaptureController.swift b/AcuantFaceCapture/AcuantFaceCapture/FaceCaptureController.swift index 2d93632..7b95e2d 100644 --- a/AcuantFaceCapture/AcuantFaceCapture/FaceCaptureController.swift +++ b/AcuantFaceCapture/AcuantFaceCapture/FaceCaptureController.swift @@ -32,9 +32,15 @@ public class FaceCaptureController: UIViewController { private var isNavigationHidden = false private let frameThrottleDuration = 0.2 private var isCaptured = false + + public var currentLangCode: String? override public func viewDidLoad() { super.viewDidLoad() + + if let currentLanguageCode = currentLangCode { + LanguageManager.shared.langCode = currentLanguageCode + } } override public func viewWillAppear(_ animated: Bool) { @@ -86,7 +92,7 @@ public class FaceCaptureController: UIViewController { queue: .main) { [weak self] _ in guard let self = self, self.alertView == nil else { return } - let alertView = AlertView(frame: self.view.bounds, text: NSLocalizedString("acuant_face_camera_paused", comment: "")) + let alertView = AlertView(frame: self.view.bounds, text: "acuant_face_camera_paused".localized) self.view.addSubview(alertView) self.alertView = alertView } @@ -111,7 +117,7 @@ public class FaceCaptureController: UIViewController { if interfaceOrientation.isLandscape { self.alertView = AlertView(frame: self.view.frame, - text: NSLocalizedString("acuant_face_camera_rotate_portrait", comment: "")) + text: "acuant_face_camera_rotate_portrait".localized) self.view.addSubview(self.alertView!) self.captureSession.stopRunning() } else if !captureSession.isRunning { @@ -334,7 +340,7 @@ public class FaceCaptureController: UIViewController { func addMessage(messageKey: String, color: CGColor? = UIColor.red.cgColor, fontSize: CGFloat = 30){ messageLayer.fontSize = fontSize messageLayer.foregroundColor = color - messageLayer.string = NSLocalizedString(messageKey, comment: "") + messageLayer.string = messageKey.localized messageLayer.frame = getMessageRect() } @@ -411,3 +417,37 @@ public class FaceCaptureController: UIViewController { return CGRect(x: 0, y: padding, width: width, height: height) } } + + +// MARK: - Custom Localization + +open class LanguageManager { + static let shared = LanguageManager() + + var langCode: String? + private(set) var currentLanguage: String + + private init() { + if let appLanguage = langCode { + currentLanguage = appLanguage + } else { + currentLanguage = Locale.current.languageCode! + } + } + + public static func localizedstring(_ key: String, comment: String = "") -> String { + let bundle = Bundle.main + guard let path = bundle.path(forResource: LanguageManager.shared.currentLanguage, ofType: "lproj"), + let string = Bundle(path: path)?.localizedString(forKey: key, value: "", table: "") else { + return NSLocalizedString(key, comment: comment) + } + return string + } + +} + +extension String { + public var localized: String { + return LanguageManager.localizedstring(self) + } +} From f54f7ecf609d2069251186587baaaaaf72cb2f0e Mon Sep 17 00:00:00 2001 From: Ruzanna Date: Wed, 16 Nov 2022 09:29:40 +0400 Subject: [PATCH 02/14] Make changes of access controls --- .../Camera/Document/DocumentCameraController.swift | 8 ++++---- .../AcuantFaceCapture/FaceCaptureController.swift | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/AcuantCamera/AcuantCamera/Camera/Document/DocumentCameraController.swift b/AcuantCamera/AcuantCamera/Camera/Document/DocumentCameraController.swift index 18c31a0..fdbbb60 100644 --- a/AcuantCamera/AcuantCamera/Camera/Document/DocumentCameraController.swift +++ b/AcuantCamera/AcuantCamera/Camera/Document/DocumentCameraController.swift @@ -514,7 +514,7 @@ extension DocumentCameraController: AutoCaptureDelegate { // MARK: - Custom Localization -open class LanguageManager { + class LanguageManager { static let shared = LanguageManager() var langCode: String? @@ -528,7 +528,7 @@ open class LanguageManager { } } - public static func localizedstring(_ key: String, comment: String = "") -> String { + public static func localizedString(_ key: String, comment: String = "") -> String { let bundle = Bundle.main guard let path = bundle.path(forResource: LanguageManager.shared.currentLanguage, ofType: "lproj"), let string = Bundle(path: path)?.localizedString(forKey: key, value: "", table: "") else { @@ -540,7 +540,7 @@ open class LanguageManager { } extension String { - public var localized: String { - return LanguageManager.localizedstring(self) + var localized: String { + return LanguageManager.localizedString(self) } } diff --git a/AcuantFaceCapture/AcuantFaceCapture/FaceCaptureController.swift b/AcuantFaceCapture/AcuantFaceCapture/FaceCaptureController.swift index 7b95e2d..9bfedab 100644 --- a/AcuantFaceCapture/AcuantFaceCapture/FaceCaptureController.swift +++ b/AcuantFaceCapture/AcuantFaceCapture/FaceCaptureController.swift @@ -435,7 +435,7 @@ open class LanguageManager { } } - public static func localizedstring(_ key: String, comment: String = "") -> String { + public static func localizedString(_ key: String, comment: String = "") -> String { let bundle = Bundle.main guard let path = bundle.path(forResource: LanguageManager.shared.currentLanguage, ofType: "lproj"), let string = Bundle(path: path)?.localizedString(forKey: key, value: "", table: "") else { @@ -447,7 +447,7 @@ open class LanguageManager { } extension String { - public var localized: String { - return LanguageManager.localizedstring(self) + var localized: String { + return LanguageManager.localizedString(self) } } From cc53cf03c70fe9f199774c880ab988e8937cd1ca Mon Sep 17 00:00:00 2001 From: Ruzanna Date: Wed, 16 Nov 2022 09:49:25 +0400 Subject: [PATCH 03/14] Change names of classes, create new groups --- .../AcuantCamera.xcodeproj/project.pbxproj | 12 +++++ .../Document/DocumentCameraController.swift | 46 +++---------------- .../LanguageManager/LanguageManager.swift | 43 +++++++++++++++++ .../AcuantCamera/View/CameraTextView.swift | 4 +- .../project.pbxproj | 12 +++++ .../FaceCaptureController.swift | 40 ++-------------- .../FaceCaptureLanguageManager.swift | 43 +++++++++++++++++ 7 files changed, 123 insertions(+), 77 deletions(-) create mode 100644 AcuantCamera/AcuantCamera/LanguageManager/LanguageManager.swift create mode 100644 AcuantFaceCapture/AcuantFaceCapture/LanguageManager/FaceCaptureLanguageManager.swift diff --git a/AcuantCamera/AcuantCamera.xcodeproj/project.pbxproj b/AcuantCamera/AcuantCamera.xcodeproj/project.pbxproj index 42fece4..89d88a2 100644 --- a/AcuantCamera/AcuantCamera.xcodeproj/project.pbxproj +++ b/AcuantCamera/AcuantCamera.xcodeproj/project.pbxproj @@ -32,6 +32,7 @@ C2B8F11F22F1D61A009811A8 /* UIScreenExtn.swift in Sources */ = {isa = PBXBuildFile; fileRef = C2B8F11E22F1D61A009811A8 /* UIScreenExtn.swift */; }; C2DC4932224BBCD20003C0CA /* AcuantCommon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C2C291F0221DC860005B4918 /* AcuantCommon.framework */; }; C2DC4933224BBCD20003C0CA /* AcuantImagePreparation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C2BB6D6D221E0F65005AFC35 /* AcuantImagePreparation.framework */; }; + CC0498452924AF7F000EF8AF /* LanguageManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC0498442924AF7F000EF8AF /* LanguageManager.swift */; }; D93A1361268F75A70047EB0E /* CameraPreviewView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D93A1360268F75A70047EB0E /* CameraPreviewView.swift */; }; D95FF40E266FB9350054E7B9 /* UInterfaceOrientationExtn.swift in Sources */ = {isa = PBXBuildFile; fileRef = D95FF40D266FB9350054E7B9 /* UInterfaceOrientationExtn.swift */; }; D95FF410266FC7E30054E7B9 /* UIWindowExtn.swift in Sources */ = {isa = PBXBuildFile; fileRef = D95FF40F266FC7E30054E7B9 /* UIWindowExtn.swift */; }; @@ -74,6 +75,7 @@ C2B8F11E22F1D61A009811A8 /* UIScreenExtn.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIScreenExtn.swift; sourceTree = ""; }; C2BB6D6D221E0F65005AFC35 /* AcuantImagePreparation.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = AcuantImagePreparation.framework; sourceTree = BUILT_PRODUCTS_DIR; }; C2C291F0221DC860005B4918 /* AcuantCommon.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = AcuantCommon.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + CC0498442924AF7F000EF8AF /* LanguageManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LanguageManager.swift; sourceTree = ""; }; D93A1360268F75A70047EB0E /* CameraPreviewView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CameraPreviewView.swift; sourceTree = ""; }; D95FF40D266FB9350054E7B9 /* UInterfaceOrientationExtn.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UInterfaceOrientationExtn.swift; sourceTree = ""; }; D95FF40F266FC7E30054E7B9 /* UIWindowExtn.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIWindowExtn.swift; sourceTree = ""; }; @@ -122,6 +124,7 @@ 134F59D421FA0BA600CEDBFC /* AcuantCamera */ = { isa = PBXGroup; children = ( + CC0498432924AF5F000EF8AF /* LanguageManager */, 836DD9A22315EA0800428964 /* View */, 8327AA4B2420161D00B524F9 /* Constant */, 8327AA4C2420165200B524F9 /* Camera */, @@ -240,6 +243,14 @@ path = View; sourceTree = ""; }; + CC0498432924AF5F000EF8AF /* LanguageManager */ = { + isa = PBXGroup; + children = ( + CC0498442924AF7F000EF8AF /* LanguageManager.swift */, + ); + path = LanguageManager; + sourceTree = ""; + }; D9B4821526BC3FED001C0CEC /* Barcode */ = { isa = PBXGroup; children = ( @@ -349,6 +360,7 @@ D95FF40E266FB9350054E7B9 /* UInterfaceOrientationExtn.swift in Sources */, 8327AA432420081100B524F9 /* StringExt.swift in Sources */, D95FF414267177A60054E7B9 /* UILayerExtn.swift in Sources */, + CC0498452924AF7F000EF8AF /* LanguageManager.swift in Sources */, 76D00240233E7C7F00CE3DA8 /* CameraOptions.swift in Sources */, C25D3BA9220B29BF003F3027 /* DocumentCaptureSession.swift in Sources */, 836DE49523204DA8005299E5 /* UIImageExtn.swift in Sources */, diff --git a/AcuantCamera/AcuantCamera/Camera/Document/DocumentCameraController.swift b/AcuantCamera/AcuantCamera/Camera/Document/DocumentCameraController.swift index fdbbb60..5363642 100644 --- a/AcuantCamera/AcuantCamera/Camera/Document/DocumentCameraController.swift +++ b/AcuantCamera/AcuantCamera/Camera/Document/DocumentCameraController.swift @@ -73,7 +73,7 @@ import AcuantCommon self.view.addGestureRecognizer(gestureRecognizer) if let currentLanguageCode = currentLangCode { - LanguageManager.shared.langCode = currentLanguageCode + DocLanguageManager.shared.langCode = currentLanguageCode } } @@ -140,7 +140,7 @@ import AcuantCommon queue: .main) { [weak self] _ in guard let self = self, self.alertView == nil else { return } - self.messageLayer.string = "acuant_camera_paused".localized + self.messageLayer.string = "acuant_camera_paused".localizedDocString let alertView = CameraAlertView(frame: self.view.bounds) self.view.addSubview(alertView) self.view.bringSubviewToFront(alertView) @@ -155,7 +155,7 @@ import AcuantCommon self.alertView?.removeFromSuperview() self.alertView = nil if !self.autoCapture { - self.messageLayer.string = "acuant_camera_manual_capture".localized + self.messageLayer.string = "acuant_camera_manual_capture".localizedDocString } } } @@ -353,7 +353,7 @@ import AcuantCommon } if let localString = localString { - self.cancelCapture(state: state, message: localString.localized) + self.cancelCapture(state: state, message: localString.localizedDocString) } else { self.setLookFromState(state: state) } @@ -431,7 +431,7 @@ extension DocumentCameraController: DocumentCaptureDelegate { public func readyToCapture() { DispatchQueue.main.async { if self.messageLayer != nil { - self.messageLayer.string = "acuant_camera_capturing".localized + self.messageLayer.string = "acuant_camera_capturing".localizedDocString if self.autoCapture { self.setLookFromState(state: DocumentCameraController.CameraState.Capture) } else { @@ -482,7 +482,7 @@ extension DocumentCameraController: FrameAnalysisDelegate { self.transitionState(state: CameraState.Hold) if self.isDocumentMoved(points: scaledPoints) { - self.cancelCapture(state: CameraState.Steady, message: "acuant_camera_hold_steady".localized) + self.cancelCapture(state: CameraState.Steady, message: "acuant_camera_hold_steady".localizedDocString) } else if !self.captured { self.triggerCapture() } @@ -505,42 +505,10 @@ extension DocumentCameraController: AutoCaptureDelegate { self.autoCapture = autoCapture if !autoCapture { DispatchQueue.main.async { - self.messageLayer.string = "acuant_camera_manual_capture".localized + self.messageLayer.string = "acuant_camera_manual_capture".localizedDocString } } } } -// MARK: - Custom Localization - - class LanguageManager { - static let shared = LanguageManager() - - var langCode: String? - private(set) var currentLanguage: String - - private init() { - if let appLanguage = langCode { - currentLanguage = appLanguage - } else { - currentLanguage = Locale.current.languageCode! - } - } - - public static func localizedString(_ key: String, comment: String = "") -> String { - let bundle = Bundle.main - guard let path = bundle.path(forResource: LanguageManager.shared.currentLanguage, ofType: "lproj"), - let string = Bundle(path: path)?.localizedString(forKey: key, value: "", table: "") else { - return NSLocalizedString(key, comment: comment) - } - return string - } - -} - -extension String { - var localized: String { - return LanguageManager.localizedString(self) - } -} diff --git a/AcuantCamera/AcuantCamera/LanguageManager/LanguageManager.swift b/AcuantCamera/AcuantCamera/LanguageManager/LanguageManager.swift new file mode 100644 index 0000000..ae8e865 --- /dev/null +++ b/AcuantCamera/AcuantCamera/LanguageManager/LanguageManager.swift @@ -0,0 +1,43 @@ +// +// LanguageManager.swift +// AcuantCamera +// +// Created by Ruzanna Sedrakyan on 16.11.22. +// Copyright © 2022 Acuant. All rights reserved. +// + +import UIKit + +// MARK: - Custom Localization + + class DocLanguageManager { + static let shared = DocLanguageManager() + + var langCode: String? + private(set) var currentLanguage: String + + private init() { + if let appLanguage = langCode { + currentLanguage = appLanguage + } else { + currentLanguage = Locale.current.languageCode! + } + } + + public static func localizedString(_ key: String, comment: String = "") -> String { + let bundle = Bundle.main + guard let path = bundle.path(forResource: DocLanguageManager.shared.currentLanguage, ofType: "lproj"), + let string = Bundle(path: path)?.localizedString(forKey: key, value: "", table: "") else { + return NSLocalizedString(key, comment: comment) + } + return string + } + +} + +extension String { + var localizedDocString: String { + return DocLanguageManager.localizedString(self) + } +} + diff --git a/AcuantCamera/AcuantCamera/View/CameraTextView.swift b/AcuantCamera/AcuantCamera/View/CameraTextView.swift index 396afab..5100006 100644 --- a/AcuantCamera/AcuantCamera/View/CameraTextView.swift +++ b/AcuantCamera/AcuantCamera/View/CameraTextView.swift @@ -31,9 +31,9 @@ public class CameraTextView: CATextLayer { super.init() self.opacity = 0.7 if autoCapture { - self.string = "acuant_camera_align".localized + self.string = "acuant_camera_align".localizedDocString } else { - self.string = "acuant_camera_manual_capture".localized + self.string = "acuant_camera_manual_capture".localizedDocString } self.alignmentMode = CATextLayerAlignmentMode.center self.cornerRadius = 10 diff --git a/AcuantFaceCapture/AcuantFaceCapture.xcodeproj/project.pbxproj b/AcuantFaceCapture/AcuantFaceCapture.xcodeproj/project.pbxproj index 43b89d5..1b44a35 100644 --- a/AcuantFaceCapture/AcuantFaceCapture.xcodeproj/project.pbxproj +++ b/AcuantFaceCapture/AcuantFaceCapture.xcodeproj/project.pbxproj @@ -16,6 +16,7 @@ 83F0BFB823D8B7E600140A06 /* AcuantFaceState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83F0BFB723D8B7E600140A06 /* AcuantFaceState.swift */; }; 83F0BFBA23D8B81200140A06 /* AcuantFaceCaptureSession.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83F0BFB923D8B81200140A06 /* AcuantFaceCaptureSession.swift */; }; 83F0BFBC23D8B87F00140A06 /* AcuantFaceDetails.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83F0BFBB23D8B87F00140A06 /* AcuantFaceDetails.swift */; }; + CC04984A2924B05B000EF8AF /* FaceCaptureLanguageManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC0498492924B05B000EF8AF /* FaceCaptureLanguageManager.swift */; }; D9395F4626C5D1EC0057EE4D /* ImagePlaceholderLayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = D9395F4526C5D1EC0057EE4D /* ImagePlaceholderLayer.swift */; }; D9395F4826C6CF910057EE4D /* AlertView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D9395F4726C6CF910057EE4D /* AlertView.swift */; }; D9395F8026C726510057EE4D /* UIWindowExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = D9395F7F26C726510057EE4D /* UIWindowExtensions.swift */; }; @@ -35,6 +36,7 @@ 83F0BFB723D8B7E600140A06 /* AcuantFaceState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AcuantFaceState.swift; sourceTree = ""; }; 83F0BFB923D8B81200140A06 /* AcuantFaceCaptureSession.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AcuantFaceCaptureSession.swift; sourceTree = ""; }; 83F0BFBB23D8B87F00140A06 /* AcuantFaceDetails.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AcuantFaceDetails.swift; sourceTree = ""; }; + CC0498492924B05B000EF8AF /* FaceCaptureLanguageManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FaceCaptureLanguageManager.swift; sourceTree = ""; }; D9395F4526C5D1EC0057EE4D /* ImagePlaceholderLayer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImagePlaceholderLayer.swift; sourceTree = ""; }; D9395F4726C6CF910057EE4D /* AlertView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlertView.swift; sourceTree = ""; }; D9395F7F26C726510057EE4D /* UIWindowExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIWindowExtensions.swift; sourceTree = ""; }; @@ -82,6 +84,7 @@ 83F0BF7323D8B28E00140A06 /* AcuantFaceCapture */ = { isa = PBXGroup; children = ( + CC0498482924B03F000EF8AF /* LanguageManager */, D9676E1A27600F39001E8B4C /* Models */, D9395F8426C727260057EE4D /* Extension */, D9395F8326C726F60057EE4D /* View */, @@ -93,6 +96,14 @@ path = AcuantFaceCapture; sourceTree = ""; }; + CC0498482924B03F000EF8AF /* LanguageManager */ = { + isa = PBXGroup; + children = ( + CC0498492924B05B000EF8AF /* FaceCaptureLanguageManager.swift */, + ); + path = LanguageManager; + sourceTree = ""; + }; D9395F8326C726F60057EE4D /* View */ = { isa = PBXGroup; children = ( @@ -214,6 +225,7 @@ 83F0BFAB23D8B59D00140A06 /* FaceCaptureController.swift in Sources */, D9676E1927600A1C001E8B4C /* FaceCaptureResult.swift in Sources */, D9395F8026C726510057EE4D /* UIWindowExtensions.swift in Sources */, + CC04984A2924B05B000EF8AF /* FaceCaptureLanguageManager.swift in Sources */, 8320597923DBA14100B7803F /* FaceCameraCornerOverlayView.swift in Sources */, D9395F4626C5D1EC0057EE4D /* ImagePlaceholderLayer.swift in Sources */, ); diff --git a/AcuantFaceCapture/AcuantFaceCapture/FaceCaptureController.swift b/AcuantFaceCapture/AcuantFaceCapture/FaceCaptureController.swift index 9bfedab..759b958 100644 --- a/AcuantFaceCapture/AcuantFaceCapture/FaceCaptureController.swift +++ b/AcuantFaceCapture/AcuantFaceCapture/FaceCaptureController.swift @@ -39,7 +39,7 @@ public class FaceCaptureController: UIViewController { super.viewDidLoad() if let currentLanguageCode = currentLangCode { - LanguageManager.shared.langCode = currentLanguageCode + FaceCaptureLanguageManager.shared.langCode = currentLanguageCode } } @@ -92,7 +92,7 @@ public class FaceCaptureController: UIViewController { queue: .main) { [weak self] _ in guard let self = self, self.alertView == nil else { return } - let alertView = AlertView(frame: self.view.bounds, text: "acuant_face_camera_paused".localized) + let alertView = AlertView(frame: self.view.bounds, text: "acuant_face_camera_paused".localizedFaceCaptureString) self.view.addSubview(alertView) self.alertView = alertView } @@ -117,7 +117,7 @@ public class FaceCaptureController: UIViewController { if interfaceOrientation.isLandscape { self.alertView = AlertView(frame: self.view.frame, - text: "acuant_face_camera_rotate_portrait".localized) + text: "acuant_face_camera_rotate_portrait".localizedFaceCaptureString) self.view.addSubview(self.alertView!) self.captureSession.stopRunning() } else if !captureSession.isRunning { @@ -340,7 +340,7 @@ public class FaceCaptureController: UIViewController { func addMessage(messageKey: String, color: CGColor? = UIColor.red.cgColor, fontSize: CGFloat = 30){ messageLayer.fontSize = fontSize messageLayer.foregroundColor = color - messageLayer.string = messageKey.localized + messageLayer.string = messageKey.localizedFaceCaptureString messageLayer.frame = getMessageRect() } @@ -419,35 +419,3 @@ public class FaceCaptureController: UIViewController { } -// MARK: - Custom Localization - -open class LanguageManager { - static let shared = LanguageManager() - - var langCode: String? - private(set) var currentLanguage: String - - private init() { - if let appLanguage = langCode { - currentLanguage = appLanguage - } else { - currentLanguage = Locale.current.languageCode! - } - } - - public static func localizedString(_ key: String, comment: String = "") -> String { - let bundle = Bundle.main - guard let path = bundle.path(forResource: LanguageManager.shared.currentLanguage, ofType: "lproj"), - let string = Bundle(path: path)?.localizedString(forKey: key, value: "", table: "") else { - return NSLocalizedString(key, comment: comment) - } - return string - } - -} - -extension String { - var localized: String { - return LanguageManager.localizedString(self) - } -} diff --git a/AcuantFaceCapture/AcuantFaceCapture/LanguageManager/FaceCaptureLanguageManager.swift b/AcuantFaceCapture/AcuantFaceCapture/LanguageManager/FaceCaptureLanguageManager.swift new file mode 100644 index 0000000..0bd3d2a --- /dev/null +++ b/AcuantFaceCapture/AcuantFaceCapture/LanguageManager/FaceCaptureLanguageManager.swift @@ -0,0 +1,43 @@ +// +// FaceCaptureLanguageManager.swift +// AcuantFaceCapture +// +// Created by Ruzanna Sedrakyan on 16.11.22. +// Copyright © 2022 Acuant. All rights reserved. +// + +import UIKit + + +// MARK: - Custom Localization + +open class FaceCaptureLanguageManager { + static let shared = FaceCaptureLanguageManager() + + var langCode: String? + private(set) var currentLanguage: String + + private init() { + if let appLanguage = langCode { + currentLanguage = appLanguage + } else { + currentLanguage = Locale.current.languageCode! + } + } + + public static func localizedString(_ key: String, comment: String = "") -> String { + let bundle = Bundle.main + guard let path = bundle.path(forResource: FaceCaptureLanguageManager.shared.currentLanguage, ofType: "lproj"), + let string = Bundle(path: path)?.localizedString(forKey: key, value: "", table: "") else { + return NSLocalizedString(key, comment: comment) + } + return string + } + +} + +extension String { + var localizedFaceCaptureString: String { + return FaceCaptureLanguageManager.localizedString(self) + } +} From 877719c9bba8295128fd34927dde4225c9870814 Mon Sep 17 00:00:00 2001 From: Ruzanna Date: Wed, 16 Nov 2022 09:56:04 +0400 Subject: [PATCH 04/14] Change access controlls --- .../AcuantCamera/LanguageManager/LanguageManager.swift | 4 ++-- .../LanguageManager/FaceCaptureLanguageManager.swift | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/AcuantCamera/AcuantCamera/LanguageManager/LanguageManager.swift b/AcuantCamera/AcuantCamera/LanguageManager/LanguageManager.swift index ae8e865..73567ba 100644 --- a/AcuantCamera/AcuantCamera/LanguageManager/LanguageManager.swift +++ b/AcuantCamera/AcuantCamera/LanguageManager/LanguageManager.swift @@ -10,7 +10,7 @@ import UIKit // MARK: - Custom Localization - class DocLanguageManager { + open class DocLanguageManager { static let shared = DocLanguageManager() var langCode: String? @@ -36,7 +36,7 @@ import UIKit } extension String { - var localizedDocString: String { + public var localizedDocString: String { return DocLanguageManager.localizedString(self) } } diff --git a/AcuantFaceCapture/AcuantFaceCapture/LanguageManager/FaceCaptureLanguageManager.swift b/AcuantFaceCapture/AcuantFaceCapture/LanguageManager/FaceCaptureLanguageManager.swift index 0bd3d2a..18d5aa1 100644 --- a/AcuantFaceCapture/AcuantFaceCapture/LanguageManager/FaceCaptureLanguageManager.swift +++ b/AcuantFaceCapture/AcuantFaceCapture/LanguageManager/FaceCaptureLanguageManager.swift @@ -37,7 +37,7 @@ open class FaceCaptureLanguageManager { } extension String { - var localizedFaceCaptureString: String { + public var localizedFaceCaptureString: String { return FaceCaptureLanguageManager.localizedString(self) } } From 572c5e5ad2062f9648f6c2e93523066d06d56865 Mon Sep 17 00:00:00 2001 From: Ruzanna Date: Wed, 16 Nov 2022 10:04:28 +0400 Subject: [PATCH 05/14] Change file locations --- AcuantCamera/AcuantCamera.xcodeproj/project.pbxproj | 10 +++++----- .../LanguageManager/DocLanguageManager.swift} | 2 +- .../AcuantFaceCapture.xcodeproj/project.pbxproj | 10 +--------- .../FaceCaptureLanguageManager.swift | 0 4 files changed, 7 insertions(+), 15 deletions(-) rename AcuantCamera/AcuantCamera/{LanguageManager/LanguageManager.swift => Camera/LanguageManager/DocLanguageManager.swift} (97%) rename AcuantFaceCapture/AcuantFaceCapture/{LanguageManager => }/FaceCaptureLanguageManager.swift (100%) diff --git a/AcuantCamera/AcuantCamera.xcodeproj/project.pbxproj b/AcuantCamera/AcuantCamera.xcodeproj/project.pbxproj index 89d88a2..5306b69 100644 --- a/AcuantCamera/AcuantCamera.xcodeproj/project.pbxproj +++ b/AcuantCamera/AcuantCamera.xcodeproj/project.pbxproj @@ -32,7 +32,7 @@ C2B8F11F22F1D61A009811A8 /* UIScreenExtn.swift in Sources */ = {isa = PBXBuildFile; fileRef = C2B8F11E22F1D61A009811A8 /* UIScreenExtn.swift */; }; C2DC4932224BBCD20003C0CA /* AcuantCommon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C2C291F0221DC860005B4918 /* AcuantCommon.framework */; }; C2DC4933224BBCD20003C0CA /* AcuantImagePreparation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C2BB6D6D221E0F65005AFC35 /* AcuantImagePreparation.framework */; }; - CC0498452924AF7F000EF8AF /* LanguageManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC0498442924AF7F000EF8AF /* LanguageManager.swift */; }; + CC0498452924AF7F000EF8AF /* DocLanguageManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC0498442924AF7F000EF8AF /* DocLanguageManager.swift */; }; D93A1361268F75A70047EB0E /* CameraPreviewView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D93A1360268F75A70047EB0E /* CameraPreviewView.swift */; }; D95FF40E266FB9350054E7B9 /* UInterfaceOrientationExtn.swift in Sources */ = {isa = PBXBuildFile; fileRef = D95FF40D266FB9350054E7B9 /* UInterfaceOrientationExtn.swift */; }; D95FF410266FC7E30054E7B9 /* UIWindowExtn.swift in Sources */ = {isa = PBXBuildFile; fileRef = D95FF40F266FC7E30054E7B9 /* UIWindowExtn.swift */; }; @@ -75,7 +75,7 @@ C2B8F11E22F1D61A009811A8 /* UIScreenExtn.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIScreenExtn.swift; sourceTree = ""; }; C2BB6D6D221E0F65005AFC35 /* AcuantImagePreparation.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = AcuantImagePreparation.framework; sourceTree = BUILT_PRODUCTS_DIR; }; C2C291F0221DC860005B4918 /* AcuantCommon.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = AcuantCommon.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - CC0498442924AF7F000EF8AF /* LanguageManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LanguageManager.swift; sourceTree = ""; }; + CC0498442924AF7F000EF8AF /* DocLanguageManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DocLanguageManager.swift; sourceTree = ""; }; D93A1360268F75A70047EB0E /* CameraPreviewView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CameraPreviewView.swift; sourceTree = ""; }; D95FF40D266FB9350054E7B9 /* UInterfaceOrientationExtn.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UInterfaceOrientationExtn.swift; sourceTree = ""; }; D95FF40F266FC7E30054E7B9 /* UIWindowExtn.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIWindowExtn.swift; sourceTree = ""; }; @@ -124,7 +124,6 @@ 134F59D421FA0BA600CEDBFC /* AcuantCamera */ = { isa = PBXGroup; children = ( - CC0498432924AF5F000EF8AF /* LanguageManager */, 836DD9A22315EA0800428964 /* View */, 8327AA4B2420161D00B524F9 /* Constant */, 8327AA4C2420165200B524F9 /* Camera */, @@ -221,6 +220,7 @@ 8327AA4C2420165200B524F9 /* Camera */ = { isa = PBXGroup; children = ( + CC0498432924AF5F000EF8AF /* LanguageManager */, D9B4821526BC3FED001C0CEC /* Barcode */, 8327AA472420086F00B524F9 /* Document */, 8327AA462420084100B524F9 /* Mrz */, @@ -246,7 +246,7 @@ CC0498432924AF5F000EF8AF /* LanguageManager */ = { isa = PBXGroup; children = ( - CC0498442924AF7F000EF8AF /* LanguageManager.swift */, + CC0498442924AF7F000EF8AF /* DocLanguageManager.swift */, ); path = LanguageManager; sourceTree = ""; @@ -360,7 +360,7 @@ D95FF40E266FB9350054E7B9 /* UInterfaceOrientationExtn.swift in Sources */, 8327AA432420081100B524F9 /* StringExt.swift in Sources */, D95FF414267177A60054E7B9 /* UILayerExtn.swift in Sources */, - CC0498452924AF7F000EF8AF /* LanguageManager.swift in Sources */, + CC0498452924AF7F000EF8AF /* DocLanguageManager.swift in Sources */, 76D00240233E7C7F00CE3DA8 /* CameraOptions.swift in Sources */, C25D3BA9220B29BF003F3027 /* DocumentCaptureSession.swift in Sources */, 836DE49523204DA8005299E5 /* UIImageExtn.swift in Sources */, diff --git a/AcuantCamera/AcuantCamera/LanguageManager/LanguageManager.swift b/AcuantCamera/AcuantCamera/Camera/LanguageManager/DocLanguageManager.swift similarity index 97% rename from AcuantCamera/AcuantCamera/LanguageManager/LanguageManager.swift rename to AcuantCamera/AcuantCamera/Camera/LanguageManager/DocLanguageManager.swift index 73567ba..f2c8377 100644 --- a/AcuantCamera/AcuantCamera/LanguageManager/LanguageManager.swift +++ b/AcuantCamera/AcuantCamera/Camera/LanguageManager/DocLanguageManager.swift @@ -1,5 +1,5 @@ // -// LanguageManager.swift +// DocLanguageManager.swift // AcuantCamera // // Created by Ruzanna Sedrakyan on 16.11.22. diff --git a/AcuantFaceCapture/AcuantFaceCapture.xcodeproj/project.pbxproj b/AcuantFaceCapture/AcuantFaceCapture.xcodeproj/project.pbxproj index 1b44a35..d6c88da 100644 --- a/AcuantFaceCapture/AcuantFaceCapture.xcodeproj/project.pbxproj +++ b/AcuantFaceCapture/AcuantFaceCapture.xcodeproj/project.pbxproj @@ -84,10 +84,10 @@ 83F0BF7323D8B28E00140A06 /* AcuantFaceCapture */ = { isa = PBXGroup; children = ( - CC0498482924B03F000EF8AF /* LanguageManager */, D9676E1A27600F39001E8B4C /* Models */, D9395F8426C727260057EE4D /* Extension */, D9395F8326C726F60057EE4D /* View */, + CC0498492924B05B000EF8AF /* FaceCaptureLanguageManager.swift */, 83F0BFAA23D8B59D00140A06 /* FaceCaptureController.swift */, 83F0BFB923D8B81200140A06 /* AcuantFaceCaptureSession.swift */, 83F0BF7423D8B28E00140A06 /* AcuantFaceCapture.h */, @@ -96,14 +96,6 @@ path = AcuantFaceCapture; sourceTree = ""; }; - CC0498482924B03F000EF8AF /* LanguageManager */ = { - isa = PBXGroup; - children = ( - CC0498492924B05B000EF8AF /* FaceCaptureLanguageManager.swift */, - ); - path = LanguageManager; - sourceTree = ""; - }; D9395F8326C726F60057EE4D /* View */ = { isa = PBXGroup; children = ( diff --git a/AcuantFaceCapture/AcuantFaceCapture/LanguageManager/FaceCaptureLanguageManager.swift b/AcuantFaceCapture/AcuantFaceCapture/FaceCaptureLanguageManager.swift similarity index 100% rename from AcuantFaceCapture/AcuantFaceCapture/LanguageManager/FaceCaptureLanguageManager.swift rename to AcuantFaceCapture/AcuantFaceCapture/FaceCaptureLanguageManager.swift From a479654bd235d30b499db82de7128d0644153bd3 Mon Sep 17 00:00:00 2001 From: Ruzanna Date: Wed, 16 Nov 2022 10:09:50 +0400 Subject: [PATCH 06/14] Change files --- .../AcuantCamera.xcodeproj/project.pbxproj | 12 ------ .../Document/DocumentCameraController.swift | 33 ++++++++++++++ .../LanguageManager/DocLanguageManager.swift | 43 ------------------- .../project.pbxproj | 4 -- .../FaceCaptureController.swift | 32 ++++++++++++++ .../FaceCaptureLanguageManager.swift | 43 ------------------- 6 files changed, 65 insertions(+), 102 deletions(-) delete mode 100644 AcuantCamera/AcuantCamera/Camera/LanguageManager/DocLanguageManager.swift delete mode 100644 AcuantFaceCapture/AcuantFaceCapture/FaceCaptureLanguageManager.swift diff --git a/AcuantCamera/AcuantCamera.xcodeproj/project.pbxproj b/AcuantCamera/AcuantCamera.xcodeproj/project.pbxproj index 5306b69..42fece4 100644 --- a/AcuantCamera/AcuantCamera.xcodeproj/project.pbxproj +++ b/AcuantCamera/AcuantCamera.xcodeproj/project.pbxproj @@ -32,7 +32,6 @@ C2B8F11F22F1D61A009811A8 /* UIScreenExtn.swift in Sources */ = {isa = PBXBuildFile; fileRef = C2B8F11E22F1D61A009811A8 /* UIScreenExtn.swift */; }; C2DC4932224BBCD20003C0CA /* AcuantCommon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C2C291F0221DC860005B4918 /* AcuantCommon.framework */; }; C2DC4933224BBCD20003C0CA /* AcuantImagePreparation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C2BB6D6D221E0F65005AFC35 /* AcuantImagePreparation.framework */; }; - CC0498452924AF7F000EF8AF /* DocLanguageManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC0498442924AF7F000EF8AF /* DocLanguageManager.swift */; }; D93A1361268F75A70047EB0E /* CameraPreviewView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D93A1360268F75A70047EB0E /* CameraPreviewView.swift */; }; D95FF40E266FB9350054E7B9 /* UInterfaceOrientationExtn.swift in Sources */ = {isa = PBXBuildFile; fileRef = D95FF40D266FB9350054E7B9 /* UInterfaceOrientationExtn.swift */; }; D95FF410266FC7E30054E7B9 /* UIWindowExtn.swift in Sources */ = {isa = PBXBuildFile; fileRef = D95FF40F266FC7E30054E7B9 /* UIWindowExtn.swift */; }; @@ -75,7 +74,6 @@ C2B8F11E22F1D61A009811A8 /* UIScreenExtn.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIScreenExtn.swift; sourceTree = ""; }; C2BB6D6D221E0F65005AFC35 /* AcuantImagePreparation.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = AcuantImagePreparation.framework; sourceTree = BUILT_PRODUCTS_DIR; }; C2C291F0221DC860005B4918 /* AcuantCommon.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = AcuantCommon.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - CC0498442924AF7F000EF8AF /* DocLanguageManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DocLanguageManager.swift; sourceTree = ""; }; D93A1360268F75A70047EB0E /* CameraPreviewView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CameraPreviewView.swift; sourceTree = ""; }; D95FF40D266FB9350054E7B9 /* UInterfaceOrientationExtn.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UInterfaceOrientationExtn.swift; sourceTree = ""; }; D95FF40F266FC7E30054E7B9 /* UIWindowExtn.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIWindowExtn.swift; sourceTree = ""; }; @@ -220,7 +218,6 @@ 8327AA4C2420165200B524F9 /* Camera */ = { isa = PBXGroup; children = ( - CC0498432924AF5F000EF8AF /* LanguageManager */, D9B4821526BC3FED001C0CEC /* Barcode */, 8327AA472420086F00B524F9 /* Document */, 8327AA462420084100B524F9 /* Mrz */, @@ -243,14 +240,6 @@ path = View; sourceTree = ""; }; - CC0498432924AF5F000EF8AF /* LanguageManager */ = { - isa = PBXGroup; - children = ( - CC0498442924AF7F000EF8AF /* DocLanguageManager.swift */, - ); - path = LanguageManager; - sourceTree = ""; - }; D9B4821526BC3FED001C0CEC /* Barcode */ = { isa = PBXGroup; children = ( @@ -360,7 +349,6 @@ D95FF40E266FB9350054E7B9 /* UInterfaceOrientationExtn.swift in Sources */, 8327AA432420081100B524F9 /* StringExt.swift in Sources */, D95FF414267177A60054E7B9 /* UILayerExtn.swift in Sources */, - CC0498452924AF7F000EF8AF /* DocLanguageManager.swift in Sources */, 76D00240233E7C7F00CE3DA8 /* CameraOptions.swift in Sources */, C25D3BA9220B29BF003F3027 /* DocumentCaptureSession.swift in Sources */, 836DE49523204DA8005299E5 /* UIImageExtn.swift in Sources */, diff --git a/AcuantCamera/AcuantCamera/Camera/Document/DocumentCameraController.swift b/AcuantCamera/AcuantCamera/Camera/Document/DocumentCameraController.swift index 5363642..6cb15c8 100644 --- a/AcuantCamera/AcuantCamera/Camera/Document/DocumentCameraController.swift +++ b/AcuantCamera/AcuantCamera/Camera/Document/DocumentCameraController.swift @@ -512,3 +512,36 @@ extension DocumentCameraController: AutoCaptureDelegate { } +// MARK: - Custom Localization + + open class DocLanguageManager { + static let shared = DocLanguageManager() + + var langCode: String? + private(set) var currentLanguage: String + + private init() { + if let appLanguage = langCode { + currentLanguage = appLanguage + } else { + currentLanguage = Locale.current.languageCode! + } + } + + public static func localizedString(_ key: String, comment: String = "") -> String { + let bundle = Bundle.main + guard let path = bundle.path(forResource: DocLanguageManager.shared.currentLanguage, ofType: "lproj"), + let string = Bundle(path: path)?.localizedString(forKey: key, value: "", table: "") else { + return NSLocalizedString(key, comment: comment) + } + return string + } + +} + +extension String { + public var localizedDocString: String { + return DocLanguageManager.localizedString(self) + } +} + diff --git a/AcuantCamera/AcuantCamera/Camera/LanguageManager/DocLanguageManager.swift b/AcuantCamera/AcuantCamera/Camera/LanguageManager/DocLanguageManager.swift deleted file mode 100644 index f2c8377..0000000 --- a/AcuantCamera/AcuantCamera/Camera/LanguageManager/DocLanguageManager.swift +++ /dev/null @@ -1,43 +0,0 @@ -// -// DocLanguageManager.swift -// AcuantCamera -// -// Created by Ruzanna Sedrakyan on 16.11.22. -// Copyright © 2022 Acuant. All rights reserved. -// - -import UIKit - -// MARK: - Custom Localization - - open class DocLanguageManager { - static let shared = DocLanguageManager() - - var langCode: String? - private(set) var currentLanguage: String - - private init() { - if let appLanguage = langCode { - currentLanguage = appLanguage - } else { - currentLanguage = Locale.current.languageCode! - } - } - - public static func localizedString(_ key: String, comment: String = "") -> String { - let bundle = Bundle.main - guard let path = bundle.path(forResource: DocLanguageManager.shared.currentLanguage, ofType: "lproj"), - let string = Bundle(path: path)?.localizedString(forKey: key, value: "", table: "") else { - return NSLocalizedString(key, comment: comment) - } - return string - } - -} - -extension String { - public var localizedDocString: String { - return DocLanguageManager.localizedString(self) - } -} - diff --git a/AcuantFaceCapture/AcuantFaceCapture.xcodeproj/project.pbxproj b/AcuantFaceCapture/AcuantFaceCapture.xcodeproj/project.pbxproj index d6c88da..43b89d5 100644 --- a/AcuantFaceCapture/AcuantFaceCapture.xcodeproj/project.pbxproj +++ b/AcuantFaceCapture/AcuantFaceCapture.xcodeproj/project.pbxproj @@ -16,7 +16,6 @@ 83F0BFB823D8B7E600140A06 /* AcuantFaceState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83F0BFB723D8B7E600140A06 /* AcuantFaceState.swift */; }; 83F0BFBA23D8B81200140A06 /* AcuantFaceCaptureSession.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83F0BFB923D8B81200140A06 /* AcuantFaceCaptureSession.swift */; }; 83F0BFBC23D8B87F00140A06 /* AcuantFaceDetails.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83F0BFBB23D8B87F00140A06 /* AcuantFaceDetails.swift */; }; - CC04984A2924B05B000EF8AF /* FaceCaptureLanguageManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC0498492924B05B000EF8AF /* FaceCaptureLanguageManager.swift */; }; D9395F4626C5D1EC0057EE4D /* ImagePlaceholderLayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = D9395F4526C5D1EC0057EE4D /* ImagePlaceholderLayer.swift */; }; D9395F4826C6CF910057EE4D /* AlertView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D9395F4726C6CF910057EE4D /* AlertView.swift */; }; D9395F8026C726510057EE4D /* UIWindowExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = D9395F7F26C726510057EE4D /* UIWindowExtensions.swift */; }; @@ -36,7 +35,6 @@ 83F0BFB723D8B7E600140A06 /* AcuantFaceState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AcuantFaceState.swift; sourceTree = ""; }; 83F0BFB923D8B81200140A06 /* AcuantFaceCaptureSession.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AcuantFaceCaptureSession.swift; sourceTree = ""; }; 83F0BFBB23D8B87F00140A06 /* AcuantFaceDetails.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AcuantFaceDetails.swift; sourceTree = ""; }; - CC0498492924B05B000EF8AF /* FaceCaptureLanguageManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FaceCaptureLanguageManager.swift; sourceTree = ""; }; D9395F4526C5D1EC0057EE4D /* ImagePlaceholderLayer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImagePlaceholderLayer.swift; sourceTree = ""; }; D9395F4726C6CF910057EE4D /* AlertView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlertView.swift; sourceTree = ""; }; D9395F7F26C726510057EE4D /* UIWindowExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIWindowExtensions.swift; sourceTree = ""; }; @@ -87,7 +85,6 @@ D9676E1A27600F39001E8B4C /* Models */, D9395F8426C727260057EE4D /* Extension */, D9395F8326C726F60057EE4D /* View */, - CC0498492924B05B000EF8AF /* FaceCaptureLanguageManager.swift */, 83F0BFAA23D8B59D00140A06 /* FaceCaptureController.swift */, 83F0BFB923D8B81200140A06 /* AcuantFaceCaptureSession.swift */, 83F0BF7423D8B28E00140A06 /* AcuantFaceCapture.h */, @@ -217,7 +214,6 @@ 83F0BFAB23D8B59D00140A06 /* FaceCaptureController.swift in Sources */, D9676E1927600A1C001E8B4C /* FaceCaptureResult.swift in Sources */, D9395F8026C726510057EE4D /* UIWindowExtensions.swift in Sources */, - CC04984A2924B05B000EF8AF /* FaceCaptureLanguageManager.swift in Sources */, 8320597923DBA14100B7803F /* FaceCameraCornerOverlayView.swift in Sources */, D9395F4626C5D1EC0057EE4D /* ImagePlaceholderLayer.swift in Sources */, ); diff --git a/AcuantFaceCapture/AcuantFaceCapture/FaceCaptureController.swift b/AcuantFaceCapture/AcuantFaceCapture/FaceCaptureController.swift index 759b958..dbd07a8 100644 --- a/AcuantFaceCapture/AcuantFaceCapture/FaceCaptureController.swift +++ b/AcuantFaceCapture/AcuantFaceCapture/FaceCaptureController.swift @@ -419,3 +419,35 @@ public class FaceCaptureController: UIViewController { } +// MARK: - Custom Localization + +open class FaceCaptureLanguageManager { + static let shared = FaceCaptureLanguageManager() + + var langCode: String? + private(set) var currentLanguage: String + + private init() { + if let appLanguage = langCode { + currentLanguage = appLanguage + } else { + currentLanguage = Locale.current.languageCode! + } + } + + public static func localizedString(_ key: String, comment: String = "") -> String { + let bundle = Bundle.main + guard let path = bundle.path(forResource: FaceCaptureLanguageManager.shared.currentLanguage, ofType: "lproj"), + let string = Bundle(path: path)?.localizedString(forKey: key, value: "", table: "") else { + return NSLocalizedString(key, comment: comment) + } + return string + } + +} + +extension String { + public var localizedFaceCaptureString: String { + return FaceCaptureLanguageManager.localizedString(self) + } +} diff --git a/AcuantFaceCapture/AcuantFaceCapture/FaceCaptureLanguageManager.swift b/AcuantFaceCapture/AcuantFaceCapture/FaceCaptureLanguageManager.swift deleted file mode 100644 index 18d5aa1..0000000 --- a/AcuantFaceCapture/AcuantFaceCapture/FaceCaptureLanguageManager.swift +++ /dev/null @@ -1,43 +0,0 @@ -// -// FaceCaptureLanguageManager.swift -// AcuantFaceCapture -// -// Created by Ruzanna Sedrakyan on 16.11.22. -// Copyright © 2022 Acuant. All rights reserved. -// - -import UIKit - - -// MARK: - Custom Localization - -open class FaceCaptureLanguageManager { - static let shared = FaceCaptureLanguageManager() - - var langCode: String? - private(set) var currentLanguage: String - - private init() { - if let appLanguage = langCode { - currentLanguage = appLanguage - } else { - currentLanguage = Locale.current.languageCode! - } - } - - public static func localizedString(_ key: String, comment: String = "") -> String { - let bundle = Bundle.main - guard let path = bundle.path(forResource: FaceCaptureLanguageManager.shared.currentLanguage, ofType: "lproj"), - let string = Bundle(path: path)?.localizedString(forKey: key, value: "", table: "") else { - return NSLocalizedString(key, comment: comment) - } - return string - } - -} - -extension String { - public var localizedFaceCaptureString: String { - return FaceCaptureLanguageManager.localizedString(self) - } -} From 182a02bf7cb54e254eeffd383d7d993f2217bf92 Mon Sep 17 00:00:00 2001 From: Ruzanna Date: Wed, 16 Nov 2022 11:00:38 +0400 Subject: [PATCH 07/14] Fix localization --- .../Document/DocumentCameraController.swift | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/AcuantCamera/AcuantCamera/Camera/Document/DocumentCameraController.swift b/AcuantCamera/AcuantCamera/Camera/Document/DocumentCameraController.swift index 6cb15c8..caa385f 100644 --- a/AcuantCamera/AcuantCamera/Camera/Document/DocumentCameraController.swift +++ b/AcuantCamera/AcuantCamera/Camera/Document/DocumentCameraController.swift @@ -517,16 +517,17 @@ extension DocumentCameraController: AutoCaptureDelegate { open class DocLanguageManager { static let shared = DocLanguageManager() - var langCode: String? - private(set) var currentLanguage: String - - private init() { - if let appLanguage = langCode { - currentLanguage = appLanguage - } else { - currentLanguage = Locale.current.languageCode! + var langCode: String? { + didSet { + if let appLanguage = langCode { + currentLanguage = appLanguage + } else { + currentLanguage = Locale.current.languageCode! + } + } } - } + + private(set) var currentLanguage: String public static func localizedString(_ key: String, comment: String = "") -> String { let bundle = Bundle.main From c2af84a6f4a02242119f53fd16b829147a2dd022 Mon Sep 17 00:00:00 2001 From: Ruzanna Date: Wed, 16 Nov 2022 11:04:17 +0400 Subject: [PATCH 08/14] Add initializer to class --- .../Camera/Document/DocumentCameraController.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/AcuantCamera/AcuantCamera/Camera/Document/DocumentCameraController.swift b/AcuantCamera/AcuantCamera/Camera/Document/DocumentCameraController.swift index caa385f..ae6b6e5 100644 --- a/AcuantCamera/AcuantCamera/Camera/Document/DocumentCameraController.swift +++ b/AcuantCamera/AcuantCamera/Camera/Document/DocumentCameraController.swift @@ -528,7 +528,10 @@ extension DocumentCameraController: AutoCaptureDelegate { } private(set) var currentLanguage: String - + + private init() { + } + public static func localizedString(_ key: String, comment: String = "") -> String { let bundle = Bundle.main guard let path = bundle.path(forResource: DocLanguageManager.shared.currentLanguage, ofType: "lproj"), From 0776b3781c5a067e166f5f2434266aad9fa76d1d Mon Sep 17 00:00:00 2001 From: Ruzanna Date: Wed, 16 Nov 2022 11:07:33 +0400 Subject: [PATCH 09/14] Return stored property in initializer --- .../Camera/Document/DocumentCameraController.swift | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/AcuantCamera/AcuantCamera/Camera/Document/DocumentCameraController.swift b/AcuantCamera/AcuantCamera/Camera/Document/DocumentCameraController.swift index ae6b6e5..e63f2aa 100644 --- a/AcuantCamera/AcuantCamera/Camera/Document/DocumentCameraController.swift +++ b/AcuantCamera/AcuantCamera/Camera/Document/DocumentCameraController.swift @@ -530,6 +530,11 @@ extension DocumentCameraController: AutoCaptureDelegate { private(set) var currentLanguage: String private init() { + if let appLanguage = langCode { + currentLanguage = appLanguage + } else { + currentLanguage = Locale.current.languageCode! + } } public static func localizedString(_ key: String, comment: String = "") -> String { From e857ec3e17bf62145ba3a31f9464d3d67b0a55f7 Mon Sep 17 00:00:00 2001 From: Ruzanna Date: Wed, 16 Nov 2022 11:24:18 +0400 Subject: [PATCH 10/14] Get device language --- .../AcuantCamera/Camera/Document/DocumentCameraController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AcuantCamera/AcuantCamera/Camera/Document/DocumentCameraController.swift b/AcuantCamera/AcuantCamera/Camera/Document/DocumentCameraController.swift index e63f2aa..c97f42b 100644 --- a/AcuantCamera/AcuantCamera/Camera/Document/DocumentCameraController.swift +++ b/AcuantCamera/AcuantCamera/Camera/Document/DocumentCameraController.swift @@ -533,7 +533,7 @@ extension DocumentCameraController: AutoCaptureDelegate { if let appLanguage = langCode { currentLanguage = appLanguage } else { - currentLanguage = Locale.current.languageCode! + currentLanguage = Locale.preferredLanguages[0]//Locale.current.languageCode! } } From da42c3565b2325745219770400d3c875e0a3ae71 Mon Sep 17 00:00:00 2001 From: Ruzanna Date: Wed, 16 Nov 2022 12:06:24 +0400 Subject: [PATCH 11/14] Get device language --- .../Camera/Document/DocumentCameraController.swift | 4 ++-- .../AcuantFaceCapture/FaceCaptureController.swift | 13 +++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/AcuantCamera/AcuantCamera/Camera/Document/DocumentCameraController.swift b/AcuantCamera/AcuantCamera/Camera/Document/DocumentCameraController.swift index c97f42b..a934321 100644 --- a/AcuantCamera/AcuantCamera/Camera/Document/DocumentCameraController.swift +++ b/AcuantCamera/AcuantCamera/Camera/Document/DocumentCameraController.swift @@ -522,7 +522,7 @@ extension DocumentCameraController: AutoCaptureDelegate { if let appLanguage = langCode { currentLanguage = appLanguage } else { - currentLanguage = Locale.current.languageCode! + currentLanguage = Locale.current.languageCode ?? "en" } } } @@ -533,7 +533,7 @@ extension DocumentCameraController: AutoCaptureDelegate { if let appLanguage = langCode { currentLanguage = appLanguage } else { - currentLanguage = Locale.preferredLanguages[0]//Locale.current.languageCode! + currentLanguage = Locale.current.languageCode ?? "en" } } diff --git a/AcuantFaceCapture/AcuantFaceCapture/FaceCaptureController.swift b/AcuantFaceCapture/AcuantFaceCapture/FaceCaptureController.swift index dbd07a8..8820e89 100644 --- a/AcuantFaceCapture/AcuantFaceCapture/FaceCaptureController.swift +++ b/AcuantFaceCapture/AcuantFaceCapture/FaceCaptureController.swift @@ -424,14 +424,23 @@ public class FaceCaptureController: UIViewController { open class FaceCaptureLanguageManager { static let shared = FaceCaptureLanguageManager() - var langCode: String? + var langCode: String? { + didSet { + if let appLanguage = langCode { + currentLanguage = appLanguage + } else { + currentLanguage = Locale.current.languageCode ?? "en" + } + } + } + private(set) var currentLanguage: String private init() { if let appLanguage = langCode { currentLanguage = appLanguage } else { - currentLanguage = Locale.current.languageCode! + currentLanguage = Locale.current.languageCode ?? "en" } } From d09fa74d9940b67dd6cdac8bd1a750712bc43874 Mon Sep 17 00:00:00 2001 From: Ruzanna Date: Mon, 28 Nov 2022 11:27:15 +0400 Subject: [PATCH 12/14] Add changes for Back button, cancel button, message labels --- .../Camera/Document/DocumentCameraController.swift | 2 +- .../AcuantFaceCapture/FaceCaptureController.swift | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/AcuantCamera/AcuantCamera/Camera/Document/DocumentCameraController.swift b/AcuantCamera/AcuantCamera/Camera/Document/DocumentCameraController.swift index a934321..4074eaa 100644 --- a/AcuantCamera/AcuantCamera/Camera/Document/DocumentCameraController.swift +++ b/AcuantCamera/AcuantCamera/Camera/Document/DocumentCameraController.swift @@ -409,7 +409,7 @@ import AcuantCommon attribs[NSAttributedString.Key.foregroundColor]=UIColor.white attribs[NSAttributedString.Key.baselineOffset]=4 - let str = NSMutableAttributedString.init(string: "BACK", attributes: attribs as [NSAttributedString.Key : Any]) + let str = NSMutableAttributedString.init(string: "acuant_back_button".localizedDocString, attributes: attribs as [NSAttributedString.Key : Any]) backButton.setAttributedTitle(str, for: .normal) backButton.addTarget(self, action: #selector(backTapped(_:)), for: .touchUpInside) backButton.isOpaque=true diff --git a/AcuantFaceCapture/AcuantFaceCapture/FaceCaptureController.swift b/AcuantFaceCapture/AcuantFaceCapture/FaceCaptureController.swift index 8820e89..68af72c 100644 --- a/AcuantFaceCapture/AcuantFaceCapture/FaceCaptureController.swift +++ b/AcuantFaceCapture/AcuantFaceCapture/FaceCaptureController.swift @@ -361,10 +361,8 @@ public class FaceCaptureController: UIViewController { view.addSubview(backButton) NSLayoutConstraint.activate([ - backButton.widthAnchor.constraint(equalToConstant: 50), - backButton.heightAnchor.constraint(equalToConstant: 50), - backButton.topAnchor.constraint(equalTo: view.topAnchor, constant: 0), - backButton.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: 0) + backButton.topAnchor.constraint(equalTo: view.topAnchor, constant: 15), + backButton.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -25) ]) } @@ -394,6 +392,7 @@ public class FaceCaptureController: UIViewController { func createMessageLayer() -> CATextLayer { messageLayer = CATextLayer() messageLayer.frame = getMessageRect() + messageLayer.isWrapped = true messageLayer.contentsScale = UIScreen.main.scale messageLayer.alignmentMode = CATextLayerAlignmentMode.center messageLayer.foregroundColor = UIColor.white.cgColor @@ -409,12 +408,13 @@ public class FaceCaptureController: UIViewController { } func getMessageRect() -> CGRect { + let sidePadding = 16.0 let width = view.safeAreaLayoutGuide.layoutFrame.size.width let topPadding = getSafeArea() let height = view.bounds.height * 0.17 let padding = topPadding == 0 ? (height - topPadding)/4 : topPadding - return CGRect(x: 0, y: padding, width: width, height: height) + return CGRect(x: sidePadding, y: padding, width: width - 2.0 * sidePadding, height: height) } } From 274737f914d7aeb796a6daab1b2f42a055dafe21 Mon Sep 17 00:00:00 2001 From: Ruzanna Date: Tue, 10 Jan 2023 10:57:57 +0400 Subject: [PATCH 13/14] Make change for label height issue --- AcuantCamera/AcuantCamera/View/CameraTextView.swift | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/AcuantCamera/AcuantCamera/View/CameraTextView.swift b/AcuantCamera/AcuantCamera/View/CameraTextView.swift index 5100006..96780d1 100644 --- a/AcuantCamera/AcuantCamera/View/CameraTextView.swift +++ b/AcuantCamera/AcuantCamera/View/CameraTextView.swift @@ -39,6 +39,11 @@ public class CameraTextView: CATextLayer { self.cornerRadius = 10 self.fontSize = textSizeDefault self.contentsScale = UIScreen.main.scale + + let newActions = [ + "fontSize": NSNull(), + ] + self.actions = newActions } func setFrame(frame: CGRect) { From 0792004d2ef12cc5e33fa40c54f191cdb8ff0850 Mon Sep 17 00:00:00 2001 From: Ruzanna Date: Fri, 20 Jan 2023 10:08:38 +0400 Subject: [PATCH 14/14] Change code for font size calculation --- .../AcuantCamera/View/CameraTextView.swift | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/AcuantCamera/AcuantCamera/View/CameraTextView.swift b/AcuantCamera/AcuantCamera/View/CameraTextView.swift index 96780d1..396a33a 100644 --- a/AcuantCamera/AcuantCamera/View/CameraTextView.swift +++ b/AcuantCamera/AcuantCamera/View/CameraTextView.swift @@ -39,11 +39,6 @@ public class CameraTextView: CATextLayer { self.cornerRadius = 10 self.fontSize = textSizeDefault self.contentsScale = UIScreen.main.scale - - let newActions = [ - "fontSize": NSNull(), - ] - self.actions = newActions } func setFrame(frame: CGRect) { @@ -64,11 +59,18 @@ public class CameraTextView: CATextLayer { } private func fitTextToFrame() { + // Calculates the string size. var stringSize: CGSize { get { return (string as? String)!.size(ofFont: UIFont(name: (font as! UIFont).fontName, size: fontSize)!) } } + + // Frame is rotating while font dimensions are stationary + let frameWidth = max(frame.width, frame.height) + let frameHeight = min(frame.width, frame.height) + + // Decreases the font size until criteria met let margin: CGFloat = 2 - while max(frame.width, frame.height) <= max(stringSize.width, stringSize.height) + margin { + while (frameWidth <= stringSize.width + margin) || frameHeight <= stringSize.height + margin { fontSize -= 1 } }