Swift: Not Return to English Version after translate to Arabic

i want to localize my apps between English and Arabic version included RTL. but it not return to English Version with left to right after translate to Arabic, it just repeats to Arabic version when i click navigation item UIButton, also navigation item flag not show properly it is just repeating Arabic flag.

// here is my code

  • iOS is it a static or a dynamic framework?
  • Api Facebook iphone , possible to post to a friend's wall
  • Python for ios interpreter
  • Maintain Session information by handling cookies in iOS
  • iOS long-running background timer with “location” background mode
  • iOS NSAttributedString to HTML
  • import UIKit
    
    import Foundation
    
    
    
    // homeCollectionViewController
    
    class HomeCollectionViewController: UICollectionViewController, UICollectionViewDelegateFlowLayout{
    
        let navLanguageBtn = UIButton()
    
        static var language = ""
    
        override func viewDidLoad() {
            super.viewDidLoad()
    
            setupHomeNavBarBtn()
    
        }
    
        // NavigationBar
        func setupHomeNavBarBtn() {
    
    
            navLanguageBtn.frame = CGRect(x: 0, y: 0, width: CollectionViewSize.width / 15, height: CollectionViewSize.width / 15)
            navLanguageBtn.contentEdgeInsets = UIEdgeInsetsMake(0, 0, CollectionViewSize.width / 60, 0)
            navLanguageBtn.setImage(UIImage(named: "arab_flag")?.withRenderingMode(.alwaysOriginal), for: .normal)
            navLanguageBtn.contentMode = .scaleAspectFit
            navLanguageBtn.addTarget(self, action: #selector(navLanguageBtnClick), for: .touchUpInside)
            let navLanguageBtnItem = UIBarButtonItem(customView: navLanguageBtn)
            self.navigationItem.setRightBarButtonItems([ navLanguageBtnItem], animated: true)
    
        }
    
    
        // ButtonClick
        public func navLanguageBtnClick(){
    
    
            if (navLanguageBtn.isSelected == true)
            {
                print("language btn click true English flag")
    
    
                navLanguageBtn.setImage(UIImage(named: "english_flag")?.withRenderingMode(.alwaysOriginal), for: UIControlState.normal)
                UIView.appearance().semanticContentAttribute = .forceRightToLeft
    
    
    
                navLanguageBtn.isSelected = false
    
                let path = Bundle.main.path(forResource: "ar-SA", ofType: "lproj")
                let bundal = Bundle.init(path: path!)! as Bundle
    
    
    
    
                HomeCollectionViewController.language = "ar"
    
    
    
                navigationItem.title = bundal.localizedString(forKey: "home", value: nil, table: nil)
    
                SecondHomeCell.newProductTrans = bundal.localizedString(forKey: "newProduct", value: nil, table: nil)
                SecondHomeCell.populerStoriesTrans = bundal.localizedString(forKey: "populerStories", value: nil, table: nil)
    
    
                let navController: UINavigationController? = (UIApplication.shared.keyWindow?.rootViewController as? UINavigationController)
                let layout = UICollectionViewFlowLayout()
                let control = HomeCollectionViewController(collectionViewLayout: layout)
    
                navController?.pushViewController(control, animated: true)
    
                let AR_POST_PARAMETERS = ["language": HomeCollectionViewController.language]
    
                self.secondHomeCell?.secondHomeCellDataLoad(POST_PARAMETERS: AR_POST_PARAMETERS as! Dictionary<String, String>)
    
            }
            else
            {
    
                print("language btn click true arabic flag")
                navLanguageBtn.setImage(UIImage(named: "arab_flag")?.withRenderingMode(.alwaysOriginal), for: UIControlState.selected)
                UIView.appearance().semanticContentAttribute = .forceLeftToRight
                // UIView.appearance().transform = CGAffineTransform(scaleX: 1.0, y: -1.0)
                navLanguageBtn.isSelected = true
    
                // self.lblCountryName.transform = CGAffineTransform(scaleX: 1.0, y: 1.0)
                let path = Bundle.main.path(forResource: "en", ofType: "lproj")
                let bundal = Bundle.init(path: path!)! as Bundle
    
    
                //home
                HomeCollectionViewController.language = "en"
    
                navigationItem.title = bundal.localizedString(forKey: "home", value: nil, table: nil)
    
                SecondHomeCell.newProductTrans = bundal.localizedString(forKey: "newProduct", value: nil, table: nil)
                SecondHomeCell.populerStoriesTrans = bundal.localizedString(forKey: "populerStories", value: nil, table: nil)
    
                let navController: UINavigationController? = (UIApplication.shared.keyWindow?.rootViewController as? UINavigationController)
                let layout = UICollectionViewFlowLayout()
                let control = HomeCollectionViewController(collectionViewLayout: layout)
    
                navController?.pushViewController(control, animated: true)
    
                let AR_POST_PARAMETERS = ["language": HomeCollectionViewController.language]
    
                self.secondHomeCell?.secondHomeCellDataLoad(POST_PARAMETERS: AR_POST_PARAMETERS as! Dictionary<String, String>)
    
            }
        }
    }
    

    Solutions Collect From Internet About “Swift: Not Return to English Version after translate to Arabic”

    For changing the language of application, from a button click within the appliaction, i suggest you to ask the user to relaunch the application, for the change to happen.

    In my application, i am changing the language like this.

    //On Button click:
    
    if applicationLanguage() == "ar"  {
                        setApplicationLanguage(languageCode: "en-US")
                    } 
    else if applicationLanguage() == "en"  {
                    setApplicationLanguage(languageCode: "ar")
                }
    
    
    
    
    func applicationLanguage() -> String
        {
            let languages : NSArray = UserDefaults.standard.object(forKey: "AppleLanguages") as! NSArray
            let selectedLanguage : String = languages[0] as! String
            return selectedLanguage.components(separatedBy: "-").first!
        }
    
    func setApplicationLanguage(languageCode : String)
        {
            // Show Alert to restart the application. Present it in your view controller.
    
    
    
            UserDefaults.standard.set([languageCode], forKey: "AppleLanguages")
            UserDefaults.standard.synchronize()
        }
    

    The user should manually quit the application, for the change to happen.