From 24f8ab969ba633eba43749f57699f00621512c99 Mon Sep 17 00:00:00 2001
From: Mustafa Merza <mustafa.merza95@gmail.com>
Date: Sun, 21 Jul 2024 11:59:20 +0300
Subject: [PATCH] - Added using localized strings for some views.

---
 .../Extensions/String+StringKeys.swift        | 10 +++
 .../KNAlert/KNAlertViewController.swift       |  5 +-
 .../EditViewController.swift                  | 16 ++--
 .../Scan/ScannerViewController.swift          |  2 +-
 .../Localization/Localizable.xcstrings        | 75 +++++++++++++++++++
 5 files changed, 96 insertions(+), 12 deletions(-)

diff --git a/MiniScanner/Extensions/String+StringKeys.swift b/MiniScanner/Extensions/String+StringKeys.swift
index 2ee2fb1..409746f 100644
--- a/MiniScanner/Extensions/String+StringKeys.swift
+++ b/MiniScanner/Extensions/String+StringKeys.swift
@@ -71,4 +71,14 @@ extension String {
     static let deviceTheme = "device_theme"
     static let darkMode = "dark_mode"
     static let lightMode = "light_mode"
+    
+    static let Continue = "continue"
+    static let back = "back"
+    
+    static let alert = "alert"
+    static let discardChangesMsg = "discard_changes_msg"
+    static let discardChangesAndContinueMsg = "discard_changes_and_continue_msg"
+    
+    static let deleteImageMsg = "delete_image_msg"
+    static let ok = "ok"
 }
diff --git a/MiniScanner/Modules/Documents/Customs/CustomViews/KNAlert/KNAlertViewController.swift b/MiniScanner/Modules/Documents/Customs/CustomViews/KNAlert/KNAlertViewController.swift
index 92e2132..971599f 100644
--- a/MiniScanner/Modules/Documents/Customs/CustomViews/KNAlert/KNAlertViewController.swift
+++ b/MiniScanner/Modules/Documents/Customs/CustomViews/KNAlert/KNAlertViewController.swift
@@ -208,7 +208,7 @@ extension KNAlertViewController {
             buttonsView_trailing.constant = buttonsView_Spacing
 
             confirmationButton.isHidden = false
-            confirmationButton.setTitle("OK", for: .normal)
+            confirmationButton.set(localized: .ok)
             buttonsView_height.constant = BUTTON_HEIGHT
             
         case .decision:
@@ -220,8 +220,7 @@ extension KNAlertViewController {
             destructiveButton.isHidden = false
             
             confirmationButton.isHidden = false
-            
-            confirmationButton.setTitle("Yes", for: .normal)
+            confirmationButton.set(localized: .yes)
 
             buttonsView_height.constant = BUTTON_HEIGHT
             
diff --git a/MiniScanner/Modules/EditViewController/EditViewController.swift b/MiniScanner/Modules/EditViewController/EditViewController.swift
index dc4aa68..ad40722 100644
--- a/MiniScanner/Modules/EditViewController/EditViewController.swift
+++ b/MiniScanner/Modules/EditViewController/EditViewController.swift
@@ -70,13 +70,13 @@ public class EditViewController: UIViewController {
         
         view.addSubview(activityIndicator)
         continueButton.backgroundColor = .mainBlue
-        continueButton.setTitle("Continue", for: .normal)
+        continueButton.set(localized: .Continue)
         continueButton.setTitleColor(.white, for: .normal)
         continueButton.layer.cornerRadius = 10
         localFileManager = LocalFileManager()
         options = ImageScannerOptions()
         configImageEditor()
-        let backButton = UIBarButtonItem(title: "Back", style: .plain, target: self, action: #selector(backTapped))
+        let backButton = UIBarButtonItem(title: .back.localized, style: .plain, target: self, action: #selector(backTapped))
         self.navigationItem.leftBarButtonItem = backButton
         
     }
@@ -105,9 +105,9 @@ public class EditViewController: UIViewController {
         if self.navigationItem.rightBarButtonItem == nil {
             self.navigationController?.popViewController(animated: true)
         } else {
-            let alertController = UIAlertController(title: "Alert", message: "Do you want to discard the changes you've made?", preferredStyle: .alert)
+            let alertController = UIAlertController(title: .alert.localized, message: .discardChangesMsg.localized, preferredStyle: .alert)
             
-            let okAction = UIAlertAction(title: "Discard", style: .destructive) { (action) in
+            let okAction = UIAlertAction(title: .discard.localized, style: .destructive) { (action) in
                     
                 self.dismiss(animated: true) {
                     if let items = self.scanSession?.scannedItems {
@@ -267,9 +267,9 @@ public class EditViewController: UIViewController {
             let bottomSheetController = NBBottomSheetController(configuration: configuration)
             bottomSheetController.present(popup, on: self)
         } else {
-            let alertController = UIAlertController(title: "Alert", message: "Do you want to discard the changes you've made and continue?", preferredStyle: .alert)
+            let alertController = UIAlertController(title: .alert.localized, message: .discardChangesAndContinueMsg.localized, preferredStyle: .alert)
             
-            let okAction = UIAlertAction(title: "Yes", style: .destructive) { (action) in
+            let okAction = UIAlertAction(title: .yes.localized, style: .destructive) { (action) in
                     
                 self.dismiss(animated: true) {
                     if let items = self.scanSession?.scannedItems {
@@ -433,9 +433,9 @@ extension EditViewController: BannerViewDelegate {
     }
     
     func delete(index: Int) {
-        let alertController = UIAlertController(title: "Alert", message: "Are you sure you want to delete this image?", preferredStyle: .alert)
+        let alertController = UIAlertController(title: .alert.localized, message: .deleteImageMsg.localized, preferredStyle: .alert)
         
-        let okAction = UIAlertAction(title: "Yes", style: .default) { (action) in
+        let okAction = UIAlertAction(title: .yes.localized, style: .default) { (action) in
             self.scanSession?.remove(index: index)
             if index != 0 {
                 self.selectedIndex = index - 1
diff --git a/MiniScanner/Supporting Files/Frameworks/CustomWeScan/Scan/ScannerViewController.swift b/MiniScanner/Supporting Files/Frameworks/CustomWeScan/Scan/ScannerViewController.swift
index 1f837ca..bb59a13 100644
--- a/MiniScanner/Supporting Files/Frameworks/CustomWeScan/Scan/ScannerViewController.swift	
+++ b/MiniScanner/Supporting Files/Frameworks/CustomWeScan/Scan/ScannerViewController.swift	
@@ -532,7 +532,7 @@ extension ScannerViewController: CustomTabBarViewDelegate {
         if multipageSession.scannedItems.isEmpty {
             self.navigationController?.popViewController(animated: false)
         } else {
-            let alertController = UIAlertController(title: "Alert",
+            let alertController = UIAlertController(title: .alert.localized,
                                                     message: .discardScannerMsg.localized, preferredStyle: .alert)
             
             let okAction = UIAlertAction(title: .discard.localized, style: .destructive, handler: { [weak self] action in
diff --git a/MiniScanner/Supporting Files/Localization/Localizable.xcstrings b/MiniScanner/Supporting Files/Localization/Localizable.xcstrings
index 768326e..7088675 100644
--- a/MiniScanner/Supporting Files/Localization/Localizable.xcstrings	
+++ b/MiniScanner/Supporting Files/Localization/Localizable.xcstrings	
@@ -35,6 +35,17 @@
         }
       }
     },
+    "alert" : {
+      "extractionState" : "manual",
+      "localizations" : {
+        "en" : {
+          "stringUnit" : {
+            "state" : "translated",
+            "value" : "Alert"
+          }
+        }
+      }
+    },
     "app_theme" : {
       "extractionState" : "manual",
       "localizations" : {
@@ -80,6 +91,23 @@
         }
       }
     },
+    "back" : {
+      "extractionState" : "manual",
+      "localizations" : {
+        "ar" : {
+          "stringUnit" : {
+            "state" : "translated",
+            "value" : "رجوع"
+          }
+        },
+        "en" : {
+          "stringUnit" : {
+            "state" : "translated",
+            "value" : "Back"
+          }
+        }
+      }
+    },
     "camera" : {
       "extractionState" : "manual",
       "localizations" : {
@@ -114,6 +142,17 @@
         }
       }
     },
+    "continue" : {
+      "extractionState" : "manual",
+      "localizations" : {
+        "en" : {
+          "stringUnit" : {
+            "state" : "translated",
+            "value" : "Continue"
+          }
+        }
+      }
+    },
     "current_page" : {
       "extractionState" : "manual",
       "localizations" : {
@@ -199,6 +238,17 @@
         }
       }
     },
+    "delete_image_msg" : {
+      "extractionState" : "manual",
+      "localizations" : {
+        "en" : {
+          "stringUnit" : {
+            "state" : "translated",
+            "value" : "Are you sure you want to delete this image?"
+          }
+        }
+      }
+    },
     "device_language" : {
       "extractionState" : "manual",
       "localizations" : {
@@ -244,6 +294,20 @@
         }
       }
     },
+    "discard_changes_and_continue_msg" : {
+      "extractionState" : "manual",
+      "localizations" : {
+        "en" : {
+          "stringUnit" : {
+            "state" : "translated",
+            "value" : "Do you want to discard the changes you've made and continue?."
+          }
+        }
+      }
+    },
+    "discard_changes_msg" : {
+      "extractionState" : "manual"
+    },
     "discard_scanner_msg" : {
       "extractionState" : "manual",
       "localizations" : {
@@ -510,6 +574,17 @@
         }
       }
     },
+    "ok" : {
+      "extractionState" : "manual",
+      "localizations" : {
+        "en" : {
+          "stringUnit" : {
+            "state" : "translated",
+            "value" : "Ok"
+          }
+        }
+      }
+    },
     "preview" : {
       "extractionState" : "manual",
       "localizations" : {
-- 
GitLab