Wednesday 21 March 2018

Localization in swift 3

step 1 : Add the Language





-->file will added like above image

Step - 2 : Add the String file

create String file and rename it as "Localizable.strings"





Step 3 : Configure String file for Localization



Step - 4 : Add the key values to get the value



note: we may check files are created in currect format or not by using cmds
  1. cd into your project root
  2. cd en.lproj - you can replace this with any localisation you are working with.
  3. plutil -lint Localizable.strings

step - 5:

we can switch the language on buttons like


  @IBAction func english(_ sender: Any) {
        
        let path = Bundle.main.path(forResource: "en", ofType: "lproj")
        let bundel = Bundle.init(path:path!)! as Bundle
   countryName.text=bundel.localizedString(forKey: "usernametitle", value: nil, table: nil)
    }
    //pt-PT.lproj

    @IBAction func protual(_ sender: Any) {
        let path = Bundle.main.path(forResource: "pt-PT", ofType: "lproj")
        let bundel = Bundle.init(path:path!)! as Bundle
        countryName.text=bundel.localizedString(forKey: "usernametitle", value: nil, table: nil)
    }



change forResource string based on language



Remove bottom line in navigation bar

navigationController ?. navigationBar . setBackgroundImage ( UIImage (), for: . any , barMetrics: . default )          navigat...