0

I have an app in which I want to localize the interface. There are just a view strings to translate.

I added localization files to storyboard so I have a similar structure like on this screeshot:

enter image description here

Now I have translated the string values on the right side of equations to the language they represent.

But if I run the app in simulator and set the scheme to use that language or even in the simulator itself set the language - i still don't get the labels translated to that language.

Which steps might I be missing?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
GeekSince1982
  • 732
  • 10
  • 25
  • check this solution may be help you http://stackoverflow.com/questions/19058499/xcode-5-ios-7-localization-not-working-in-simulator – jogshardik May 04 '15 at 12:24
  • What version of Xcode are you using? Some recent versions had trouble displaying localized resources in the Simulator. Have you tried running your app on an actual device and switching the language? – Michael Teper May 13 '15 at 19:56

1 Answers1

4

It is very simple to perform localisation in ios, please follow the below steps.

  1. Create a xcode project like : LocalizationDemo

  2. Design the storyboard, with labels as screen shot below.

enter image description here

  1. Click on the project, under navigation select project. Under localizations click +(plus) button and select the preferred language. as below.

enter image description here

  1. Create a "Localizable.strings" by right click on project folder, click new file, choose the template IOS, under resources select "String File" and give the name "Localizable".

  2. Select the Localizable.strings file from project navigator, on the right most corner use can see as below,

    enter image description here

  3. Click on the localize, then you will see a pop up , select Base. Later click on Localization.strings file on the right side select the preferred languages as below.

enter image description here

  1. Under Localization.strings, select the preferred .strings file and declare the Keys and values for the labels of storyboard, as below

enter image description here

  1. Get the translated text from goole or from your client.

  2. Create a swift file like: StringExtension.swift , under that file write the code as below.

    import Foundation
    
    let LANGUAGE = "te-IN"
    
    extension String {
    
      //code for swift 2.3
    
      func localized() -> String {
    
         let path = NSBundle.mainBundle().pathForResource(LANGUAGE, ofType:  "lproj")
    
         let bundle = NSBundle(path: path!)
    
         return NSLocalizedString(self, tableName: nil, bundle: bundle!,   value: "", comment: "")
    
     }
    
    
     //Code for Swift 3.0
    
     func localized() -> String{
    
        let path = Bundle.main.path(forResource: LANGUAGE, ofType: "lproj")
        let bundle = Bundle(path: path!)
    
        return NSLocalizedString(self, tableName: nil, bundle: bundle!,      value: "", comment: "")
       }
     }
    
  3. When you click the language specific localization.strings file, on right side you can see the "te-IN" as below,

enter image description here

  1. Create the outlets of labels in viewcontroller, and in viewdidload write the code as below,

    welcomeLbl.text = "Welcome".localized()
    
    haiLbl.text = "Hai how are you?".localized()
    
  2. Finally the language and images are just for reference.

Mahendra
  • 8,448
  • 3
  • 33
  • 56
Arshad Shaik
  • 1,095
  • 12
  • 18