diff --git a/LocalizationHelperDemo/LocalizationHelperDemo.xcodeproj/xcuserdata/moathaliwat.xcuserdatad/xcschemes/LocalizationHelperDemo.xcscheme b/LocalizationHelperDemo/LocalizationHelperDemo.xcodeproj/xcuserdata/moathaliwat.xcuserdatad/xcschemes/LocalizationHelperDemo.xcscheme
index 0185a9d..6d10bb4 100644
--- a/LocalizationHelperDemo/LocalizationHelperDemo.xcodeproj/xcuserdata/moathaliwat.xcuserdatad/xcschemes/LocalizationHelperDemo.xcscheme
+++ b/LocalizationHelperDemo/LocalizationHelperDemo.xcodeproj/xcuserdata/moathaliwat.xcuserdatad/xcschemes/LocalizationHelperDemo.xcscheme
@@ -27,8 +27,6 @@
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
-
-
-
-
+
+
-
-
-
-
-
-
+
+
-
+
@@ -14,7 +12,7 @@
-
+
@@ -38,7 +36,7 @@
-
+
-
+
-
-
+
+
-
-
+
diff --git a/LocalizationHelperDemo/LocalizationHelperDemo/ViewController.swift b/LocalizationHelperDemo/LocalizationHelperDemo/ViewController.swift
index d3fdf59..7d1b0c3 100644
--- a/LocalizationHelperDemo/LocalizationHelperDemo/ViewController.swift
+++ b/LocalizationHelperDemo/LocalizationHelperDemo/ViewController.swift
@@ -11,7 +11,7 @@ import UIKit
class ViewController: UIViewController {
@IBOutlet weak var programmaticallylocalizedLabel: UILabel!
@IBOutlet var labelWithFont: MOLHFontLocalizableLabel!
- @IBOutlet var textField: UITextField!
+ @IBOutlet var textField: TextView!
@IBOutlet var arrowImage: UIImageView! {
didSet {
arrowImage.image = arrowImage.image?.flipIfNeeded()
@@ -21,18 +21,42 @@ class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// textField.forceSwitchingRegardlessOfTag = true
- self.programmaticallylocalizedLabel.text = NSLocalizedString("localize me please", comment: "Localize me Label in the main scene")
+ self.programmaticallylocalizedLabel.text = NSLocalizedString("localize_me_please", comment: "Localize me Label in the main scene")
+
self.labelWithFont.updateFont()
-// NotificationCenter.default.addObserver(self, selector: #selector(inputModeDidChange), name: .UITextInputCurrentInputModeDidChange, object: nil)
+
+ let identifiers : NSArray = NSLocale.availableLocaleIdentifiers as NSArray
+ let locale = NSLocale(localeIdentifier: "en_US")
+ let list = NSMutableString()
+ for identifier in identifiers {
+ let name = locale.displayName(forKey: NSLocale.Key.identifier, value: identifier)!
+ list.append("\(identifier)\t\(name)\n")
+ }
+ if #available(iOS 13.0, *) {
+ labelWithFont.isUserInteractionEnabled = true
+ let interaction = UIContextMenuInteraction(delegate: self)
+ labelWithFont.addInteraction(interaction)
+
+ } else {
+ // Fallback on earlier versions
+ }
+ self.programmaticallylocalizedLabel.text = Locale.current.identifier
+// let view = UIView()
+// view.frame = CGRect(origin: .zero, size: CGSize(width: 100, height: 400))
+// view.backgroundColor = .red
+// print("current local", Locale.current.identifier)
+// textField.inputView = view
+ NotificationCenter.default.addObserver(self, selector: #selector(inputModeDidChange), name: UITextInputMode.currentInputModeDidChangeNotification, object: nil)
}
-// @objc func inputModeDidChange(_ notification: Notification) {
+ @objc func inputModeDidChange(_ notification: Notification) {
+
// if let language = self.textInputMode?.primaryLanguage, MOLHLanguage.isRTLLanguage(language: language) {
// textField.textAlignment = .right
// } else {
// textField.textAlignment = .left
// }
-// }
+ }
@IBAction func switchTheLanguage(_ sender: UIButton) {
MOLH.setLanguageTo(MOLHLanguage.currentAppleLanguage() == "en" ? "ar" : "en")
@@ -47,6 +71,166 @@ class ViewController: UIViewController {
sender.resignFirstResponder()
}
+
+
+
+// override var textInputMode: UITextInputMode?{
+// print("Total number of keyboards. : \(UITextInputMode.activeInputModes.count)")
+//
+// for keyboardInputModes in UITextInputMode.activeInputModes {
+// if let language = keyboardInputModes.primaryLanguage {
+// if language == "ar" {
+// print("success")
+// return keyboardInputModes;
+// }
+// }
+// }
+//
+// print("failed")
+// return super.textInputMode;
+// }
+}
+//extension UIResponder {
+// open var textInputMode: UITextInputMode? {
+// CustomTextInput()
+// }
+//}
+
+class CustomTextInput: UITextInputMode {
+ override var primaryLanguage: String? {
+ return "fr"
+ }
+}
+
+extension UIViewController {
+ @objc open override var textInputMode: UITextInputMode? {
+ CustomTextInput()
+ }
+}
+
+final class TextView: UITextField {
+// private var preferredTextInputModePrimaryLanguage: String? = "en"
+//
+// /**
+// Use given primary language for the preferred text input mode when next time text view becomes first responder.
+// - Parameters:
+// - primaryLanguage: `String` represents a primary language for the preferred text input mode. Use `"emoji"` to use Emoji keyboard.
+// */
+// func usePreferredTextInputModePrimaryLanguage(_ primaryLanguage: String) {
+// preferredTextInputModePrimaryLanguage = primaryLanguage
+// }
+//
+// /**
+// # UIKit Bug Workaround
+// - Confirmed on iOS 13.0 to iOS 13.3.
+// - Fixed on iOS 13.4.
+// `textInputMode` override is completely ignored on these version of iOS 13 due to bug in `-[UIKeyboardImpl recomputeActiveInputModesWithExtensions:allowNonLinguisticInputModes:]`,
+// which has a flipped condition check, which doesn't always call `-[UIKeyboardImpl setInputMode:userInitiated:]`.
+// To workaround this behavior, return non `nil` identifier from `textInputContextIdentifier` to call `-[UIKeyboardImpl setInputMode:userInitiated:]` from
+// `-[UIKeyboardInputModeController _trackInputModeIfNecessary:]` and bypass `-[UIKeyboardImpl recomputeActiveInputModesWithExtensions:allowNonLinguisticInputModes:]` call.
+// Also need to clean up text input context identifier once it’s used for the bug workaround.
+// - See also:
+// - `becomeFirstResponder()`
+// - `textInputContextIdentifier`
+// - `textInputMode`
+// */
+// private let shouldWorkaroundTextInputModeBug: Bool = {
+// // iOS 13.0 to iOS 13.3
+// if #available(iOS 13.0, *) {
+// if #available(iOS 13.4, *) {
+// return false
+// } else {
+// return true
+// }
+// }
+// return false
+// }()
+//
+// private let preferredTextInputModeContextIdentifier = ".preferredTextInputModeContextIdentifier"
+//
+// override func becomeFirstResponder() -> Bool {
+// let result = super.becomeFirstResponder()
+// if result {
+// if shouldWorkaroundTextInputModeBug {
+// UIResponder.clearTextInputContextIdentifier(preferredTextInputModeContextIdentifier)
+// }
+// preferredTextInputModePrimaryLanguage = "en"
+// }
+// return result
+// }
+//
+// override var textInputContextIdentifier: String? {
+// if shouldWorkaroundTextInputModeBug, preferredTextInputModePrimaryLanguage != nil {
+// return preferredTextInputModeContextIdentifier
+// }
+//
+// return super.textInputContextIdentifier
+// }
+//
+// override var textInputMode: UITextInputMode? {
+// if
+// let inputMode = UITextInputMode.activeInputModes.first(where: { $0.primaryLanguage?.contains("en") ?? false }) {
+// return inputMode
+// }
+//
+// return super.textInputMode
+// }
}
+extension ViewController: UIContextMenuInteractionDelegate {
+ @available(iOS 13.0, *)
+ func contextMenuInteraction(_ interaction: UIContextMenuInteraction, configurationForMenuAtLocation location: CGPoint) -> UIContextMenuConfiguration? {
+
+ if #available(iOS 13.0, *) {
+
+ let identifier = "\(location.debugDescription)" as NSString
+
+ let info = UIAction(
+ title: "ارابيم",
+ image: UIImage(systemName: "info.circle")) { _ in
+ }
+ let mute = UIAction(
+ title: "L10n.mute",
+ image: UIImage(systemName: "speaker.slash")) { _ in
+ //self.showAlert("Error", message: "Implement mute action", handler: nil)
+ }
+
+ let delete = UIAction(
+ title: "زيايل",
+ image: UIImage(systemName: "trash")) { _ in
+
+ }
+
+ let audioCall = UIAction(
+ title: "نمستي رخه",
+ image: UIImage(systemName: "phone")) { _ in
+ }
+
+ let videoCall = UIAction(
+ title: "L10n.videoCall",
+ image: UIImage(systemName: "video")) { _ in
+ }
+
+ _ = UIAction(
+ title: "L10n.exitGroup",
+ image: UIImage(systemName: "person.3")) { _ in
+ }
+
+ var menu = UIMenu()
+
+ menu = UIMenu(title: "", children: [info, mute, delete, audioCall, videoCall])
+
+
+ return UIContextMenuConfiguration(
+ identifier: identifier,
+ previewProvider: nil) { _ in
+ return menu
+ }
+ } else {
+ // Fallback on earlier versions
+ return nil
+ }
+
+ }
+}
diff --git a/LocalizationHelperDemo/LocalizationHelperDemo/agq-CM.lproj/Localizable.strings b/LocalizationHelperDemo/LocalizationHelperDemo/agq-CM.lproj/Localizable.strings
index df66c7e..b2f63ff 100644
--- a/LocalizationHelperDemo/LocalizationHelperDemo/agq-CM.lproj/Localizable.strings
+++ b/LocalizationHelperDemo/LocalizationHelperDemo/agq-CM.lproj/Localizable.strings
@@ -5,4 +5,4 @@
Created by Moath_Othman on 3/6/16.
Copyright © 2016 Moath_Othman. All rights reserved.
*/
-"localize me please" = "localize me please";
+"localize_me_please" = "localize me please cameroon";
diff --git a/LocalizationHelperDemo/LocalizationHelperDemo/ar.lproj/Localizable.strings b/LocalizationHelperDemo/LocalizationHelperDemo/ar.lproj/Localizable.strings
index 363d7b7..b0f43e8 100644
--- a/LocalizationHelperDemo/LocalizationHelperDemo/ar.lproj/Localizable.strings
+++ b/LocalizationHelperDemo/LocalizationHelperDemo/ar.lproj/Localizable.strings
@@ -5,4 +5,4 @@
Created by Moath_Othman on 3/6/16.
Copyright © 2016 Moath_Othman. All rights reserved.
*/
-"localize me please" = "لوكالايز مي";
+"localize_me_please" = "لوكالايز مي";
diff --git a/LocalizationHelperDemo/LocalizationHelperDemo/ckb-IQ.lproj/Localizable.strings b/LocalizationHelperDemo/LocalizationHelperDemo/ckb-IQ.lproj/Localizable.strings
index df66c7e..7b6f6f8 100644
--- a/LocalizationHelperDemo/LocalizationHelperDemo/ckb-IQ.lproj/Localizable.strings
+++ b/LocalizationHelperDemo/LocalizationHelperDemo/ckb-IQ.lproj/Localizable.strings
@@ -5,4 +5,4 @@
Created by Moath_Othman on 3/6/16.
Copyright © 2016 Moath_Othman. All rights reserved.
*/
-"localize me please" = "localize me please";
+"localize_me_please" = "localize me please sorani";
diff --git a/LocalizationHelperDemo/LocalizationHelperDemo/ckb-IR.lproj/Localizable.strings b/LocalizationHelperDemo/LocalizationHelperDemo/ckb-IR.lproj/Localizable.strings
index df66c7e..7b6f6f8 100644
--- a/LocalizationHelperDemo/LocalizationHelperDemo/ckb-IR.lproj/Localizable.strings
+++ b/LocalizationHelperDemo/LocalizationHelperDemo/ckb-IR.lproj/Localizable.strings
@@ -5,4 +5,4 @@
Created by Moath_Othman on 3/6/16.
Copyright © 2016 Moath_Othman. All rights reserved.
*/
-"localize me please" = "localize me please";
+"localize_me_please" = "localize me please sorani";
diff --git a/LocalizationHelperDemo/LocalizationHelperDemo/en.lproj/Localizable.strings b/LocalizationHelperDemo/LocalizationHelperDemo/en.lproj/Localizable.strings
index df66c7e..96156d8 100644
--- a/LocalizationHelperDemo/LocalizationHelperDemo/en.lproj/Localizable.strings
+++ b/LocalizationHelperDemo/LocalizationHelperDemo/en.lproj/Localizable.strings
@@ -5,4 +5,4 @@
Created by Moath_Othman on 3/6/16.
Copyright © 2016 Moath_Othman. All rights reserved.
*/
-"localize me please" = "localize me please";
+"localize_me_please" = "localize me please";
diff --git a/LocalizationHelperDemo/LocalizationHelperDemo/he-IL.lproj/Localizable.strings b/LocalizationHelperDemo/LocalizationHelperDemo/he-IL.lproj/Localizable.strings
index df66c7e..8a22c76 100644
--- a/LocalizationHelperDemo/LocalizationHelperDemo/he-IL.lproj/Localizable.strings
+++ b/LocalizationHelperDemo/LocalizationHelperDemo/he-IL.lproj/Localizable.strings
@@ -5,4 +5,4 @@
Created by Moath_Othman on 3/6/16.
Copyright © 2016 Moath_Othman. All rights reserved.
*/
-"localize me please" = "localize me please";
+"localize_me_please" = "localize me please hebrew";
diff --git a/LocalizationHelperDemo/LocalizationHelperDemo/ur.lproj/Localizable.strings b/LocalizationHelperDemo/LocalizationHelperDemo/ur.lproj/Localizable.strings
index df66c7e..8148082 100644
--- a/LocalizationHelperDemo/LocalizationHelperDemo/ur.lproj/Localizable.strings
+++ b/LocalizationHelperDemo/LocalizationHelperDemo/ur.lproj/Localizable.strings
@@ -5,4 +5,4 @@
Created by Moath_Othman on 3/6/16.
Copyright © 2016 Moath_Othman. All rights reserved.
*/
-"localize me please" = "localize me please";
+"localize_me_please" = "localize me please urdu";
diff --git a/Sources/MOLH/MOLH.swift b/Sources/MOLH/MOLH.swift
index 1a15717..0752512 100644
--- a/Sources/MOLH/MOLH.swift
+++ b/Sources/MOLH/MOLH.swift
@@ -117,9 +117,9 @@ open class MOLH {
**@note** swizzling extension could lead to issues if you are swizzling your UIViews **layoutSubviews** method from another place
*/
open func activate(_ swizzleExtensions: Bool = false) {
- //invitable swizzlings first for the localzation itself (bundle switch) and the other for the direction (not needed if you support ios 9 and up)
swizzle(class: Bundle.self, sel: #selector(Bundle.localizedString(forKey:value:table:)), override: #selector(Bundle.specialLocalizedStringForKey(_:value:table:)))
-
+ swizzle(class:UIApplication.self, sel: #selector(getter: UIApplication.userInterfaceLayoutDirection), override: #selector(getter: UIApplication.cstm_userInterfaceLayoutDirection))
+
if swizzleExtensions {
swizzle(class:UIViewController.self, sel: #selector(UIViewController.viewDidLayoutSubviews), override: #selector(UIViewController.mirroringviewDidLoad))
swizzle(class:UIControl.self, sel: #selector(UIControl.awakeFromNib), override: #selector(UIControl.cstmlayoutSubviews))
@@ -189,6 +189,18 @@ open class MOLH {
}
}
+extension UIApplication {
+ @objc var cstm_userInterfaceLayoutDirection : UIUserInterfaceLayoutDirection {
+ get {
+ var direction = UIUserInterfaceLayoutDirection.leftToRight
+ if MOLHLanguage.isRTLLanguage() {
+ direction = .rightToLeft
+ }
+ return direction
+ }
+ }
+}
+
extension Bundle {
@objc func specialLocalizedStringForKey(_ key: String, value: String?, table tableName: String?) -> String {
// check if its the main bundle then if the bundle of the current language is available