Internationalization and localization of Apps in Xcode 6 and Swift

Internationalisation and Localization of apps is essential when you want the apps to seamlessly support different languages and region. Internationalization refers to process of providing a framework to the app for supporting multiple languages. And Localization refers to the process of making your app to support a particular locale such as German

In this tutorial, we are going to see an example app that supports text, number, date, currency and image localisation for English and German languages. This is done by following the below mentioned steps

  • Use NSNumberFormatter, NSDateFormatter for Number, Currency and Date values.
  • Internationalization of Storyboard.
  • Internationalization of text.
  • Internationalization of images.






Download source code from GitHub

Create a new project by clicking File menu -> New -> Project


Select the template for the Project as Single View Application.


In the next screen, provide a name for the project as “Localisation Demo” and select the Language as “Swift” then specify a location and save the project.

User Interface changes – UILabels and UIImageView on ViewController


Navigate to Main.storyboard, click default View Controller. Drag and drop 9 Labels and 1 ImageView from Object Library on to Storyboard. These labels are used for displaying the caption and values as shown in the below screenshot.


Declaring IBOutlets for UIControls

Click ViewController.swift in project navigator and add the following IBOutlets after the class declaration.

@IBOutlet var textLabel: UILabel!

@IBOutlet var numberLabel: UILabel!

@IBOutlet var currencyLabel: UILabel!

@IBOutlet var dateLabel: UILabel!

@IBOutlet var imageView: UIImageView!

Navigate back to Main.storyboard and connect labels and imageView to the respective outlets.


Populate values for the controls.


Click ViewController.swift in Project Navigator and create a new function with name as populateValues

func populateValues() {
textLabel.text = “Good Morning”
numberLabel.text = “9999999.999”
currencyLabel.text = “50000”
dateLabel.text = “07/08/2014”
imageView.image = UIImage(named: “hello”)

The above function populates values for all the controls. The values which are assigned for the fields will be displayed in the screen without localization format. Then add this function as part of ViewDidLoad function.

override func viewDidLoad() {

Using Add Files to option, add the image hello.png to the Project folder.


Now if you compile and run the project on iOS simulator, you should see the follow screen with values for the labels and image view.


We do not see any formatting applied for Number, Date and Currency Values. Now let us see how to use NSNumberFormatter for formatting number and currency field and NSDateFormatter for formatting date field. Add the following properties after populateValues function in ViewController.swift file.

var numberFormatter: NSNumberFormatter {
	let formatter = NSNumberFormatter()
	formatter.numberStyle = .DecimalStyle
	return formatter

var currencyFormatter: NSNumberFormatter {
	let formatter = NSNumberFormatter()
	formatter.numberStyle = .CurrencyStyle
	return formatter


var dateFormatter: NSDateFormatter {
	let formatter = NSDateFormatter()
	formatter.dateStyle = .MediumStyle
	formatter.timeStyle = .MediumStyle
	return formatter


In the above functions, we are creating respective formatter instances and setting the corresponding styles such DecimalStyle, CurrencyStyle then MediumStyle for date and time values. Now we need to update populateValues function to use these properties for displaying the values.

func populateValues() {
	textLabel.text = “Good Morning”
	numberLabel.text = numberFormatter.stringFromNumber(9999999.999)
	currencyLabel.text = currencyFormatter.stringFromNumber(5000)
	dateLabel.text = dateFormatter.stringFromDate(NSDate())
	imageView.image = UIImage(named: “hello”)

Now after applying the correct format, iOS Simulator will use the default system region to display the values for number, currency and date fields


Adding support for another language to your Xcode Project

In order to enable support for German language, first we need to add that language to the Project. This can be done by using the option available as part of Project target. Select the Project folder then the Project target.


Navigate to the Localization section and click the + sign then select German (de) from the list.


Choose the default files listed in the below screen and click Finish.


Now you should see support German language under Localizations section.


Add Localization for controls in Storyboard

First let us see how to add support for another language for the Caption controls in Main.storyboard.


Expand Main.storyboard and click Main.strings (German) . Now enter the German equivalent for Date, Currency, Number and Image as Datum, Währung, Anzahl and Bild. And for rest of the controls, localization will be done in the code.


/* Class = “IBUILabel”; text = “Date :”; ObjectID = “0sh-CK-26C”; */
“0sh-CK-26C.text” = “Datum :”;

/* Class = “IBUILabel”; text = “Number :”; ObjectID = “AeO-ot-XWj”; */
“AeO-ot-XWj.text” = “Anzahl :”;

/* Class = “IBUILabel”; text = “number”; ObjectID = “XDV-eF-gQk”; */
“XDV-eF-gQk.text” = “number”;

/* Class = “IBUILabel”; text = “Image :”; ObjectID = “bvG-x6-Tpx”; */
“bvG-x6-Tpx.text” = “Bild :”;

/* Class = “IBUILabel”; text = “Currency :”; ObjectID = “tVi-KF-Xgb”; */
“tVi-KF-Xgb.text” = “Währung :”;

Testing Localization changes in iOS Simulator

The changes to Main.storyboard (German) and NSNumberFormatter and NSDateFormatter will have no effect until we set the language and region to German in Xcode debug environment. Click Set the active scheme option and select Edit Scheme from the list.


Navigate to Options under Debug Environment and select German and Germany for Application Language and Application Region.


Now running the app on the iOS simulator should display the captions in german language and apply formats for number, date and currency fields based on German region.


Internationalization of Text using NSLocalizedString

“Good Morning” has to be displayed in the corresponding German language i.e “Guten Morgen”. Add a new File to the project of type Strings and provide a name as Localizable.strings.


Select Localizable.Strings in Project Navigator and click Localize button available under File Inspector.


Then Select English in the Localize drop down and make sure to mark German in the Localization section under File Inspector.


Now you should be able to expand Localizable.Strings under Project Navigator and see separate files for English and German.


Add the following line in Localizable.Strings (English)

GOOD_MORNING=“Good Morning”;

Add the following line in Localizable.Strings (German)

GOOD_MORNING=“Guten Morgen”;

Now add the corresponding code to use the values from Localizable.Strings file. Click ViewController.swift and change

textLabel.text = “Good Morning”


textLabel.text = NSLocalizedString(“GOOD_MORNING”,comment:“Good Morning”)

NSLocalizedString will lookup for the corresponding entry in Localizable.Strings file for the supplied key. Running the app on iOS simulator should not display the German equivalent for “Good Morning”


Internationalization of Images

In the above screenshot, you could see that text in the image is still in English. So we need to add the corresponding image that contains German text and make changes to pick up the entry based on the Application Language. After selecting hello.png in Project navigator, click Localize button under File Inspector. This should provide you with the option to Localize the file in English and German.


Make sure to tick both English and German under Localization section in File Inspector.


Open the Project folder in Finder tool and this should contain two folder for the languages de and en.


Now copy hello.png with german text to de.lproj folder. Do a clean build and run the app on iOS simulator with language and region set to German.


Download source code from GitHub

In Category: ios, iPad, iPhone, Programming, Xcode

Ravi Shankar

A polyglot software developer and now exploring Swift and iOS development. If you would like to learn from me then check out services page.

Show 24 Comments
  • Isuru August 13, 2014, 7:22 pm

    Thank you so much for the tutorial. I think this is the first and currently the only tutorial on internationalization and localization in Swift. I’ve been looking for one for the past couple of weeks. Learned a lot. Thank you again.

  • Ignatius September 8, 2014, 6:54 pm

    On Xcode6’s changelog appears this: “Implicit .strings file. Xcode automatically generates the base language .strings file directly from your source code—now you no longer need to manage this .strings file by hand.”

    Do you know how to generate this file automatically?

  • Djandji September 22, 2014, 3:01 pm

    Thank you for this very helpful tutorial !

    However, I do have one question:

    In some string, I have so interpolation, such as “At\(currentWeather.currentTime!) it is”

    If I do the translation in French of this sentence, I put in my localizable file: “À \(currentWeather.currentTime!) il fait”

    However, this prints me in the simulator, the exact text, and not the currentTime I am looking for by interpolation…
    any solution?

    • rshankar September 23, 2014, 4:51 am

      I have not tried this but just a thought. How about separating “At\(currentWeather.currentTime!) it is” in to three parts, “At” + “\(currentWeather.currentTime!)” + “it is”. Then add the first and last string to the localised file. Will that work?

  • German User September 30, 2014, 2:48 pm

    In Germany were are saying “Guten Morgen”, not “Guten Morgan”

    • rshankar September 30, 2014, 2:50 pm

      Thanks, now the tutorial is update with correct spelling.

  • Samin Shams October 20, 2014, 7:29 pm

    With your demo, when I change the iOS Deployment Target to 7.0 and change the Devices to Universal, the Main.storyboard stops localising. Is it just my Xcode that does that?

  • Martin Lok October 30, 2014, 9:00 pm

    Thanks a lot! Simple and great tutorial

  • John Belbute November 6, 2014, 12:12 am

    Great article! One suggestion though. The file Localizable.strings above has the .Strings file with a capital S. That will not work, the s has to be lower case

    • rshankar November 9, 2014, 3:45 am

      Thanks for the suggestion.

  • Aral Balkan February 5, 2015, 2:07 pm

    Thanks for the article. One note: In Xcode 6, you can actually export and import XLIFF ( files.

    Select the project and then: Editor (Menu) → Export for/Import localization(s)…

    This makes it very easy to have others help you to iteratively localise your apps without requiring access to the Xcode project.

  • Mike February 20, 2015, 7:35 pm

    Great article and very helpful!
    But in my special case I have a string array with about 50 strings in it. Each string of the array is displayed by random. How can I translate this (string) array?

    For example:
    var days = [“Monday”, “Tuesday”, “Wednesday”]

    How do I write this in the localizable.strings and how I write

    textLabel.text = NSLocalizedString(“GOOD_MORNING”,comment:“Good Morning”) with and (index) for my random generation?

    • Holroy February 24, 2015, 8:06 pm

      Isn’t that just to replace your array initialisation with the localized version, add the strings and use the array as before?

      var days = [
      NSLocalizedString(“MONDAY”, comment: “Monday”),
      NSLocalizedString(“TUESDAY”, comment: “Tuesday”),
      NSLocalizedString(“WEDNESDAY”, comment: “Wednesday”),

  • hamed March 3, 2015, 12:09 pm

    i need to change app language
    programmatically , make the user choose his preferred language

  • Max March 9, 2015, 11:09 am

    NSLocalizedString(“GOOD_MORNING”,comment:”Good Morning”)
    had return key “GOOD_MORNING”

    • Sadaf January 7, 2016, 10:07 am

      I am facing the same problem, did you find how to fix it?

  • Chinna June 15, 2015, 12:31 pm

    Hi it’s Really Great article ThankQ soooo much!

    i faced one problem after creating the Localization.string file i am trying to add some text(TESTING=“Hi dis is german Language”) to that file i am getting error like “/Users/XXXXXX/Desktop/FirstDemo/FirstDemo/en.lproj/Localizable.strings:0: error: read failed: The data couldn’t be read because it isn’t in the correct format.” where i did the mistake please help me some one

    in Advance Thanks

  • Roger December 7, 2015, 7:56 am

    Great step-by-step tutorial! Really clears things on localization in Swift. Thank you Ravi.

  • Afshin December 25, 2015, 6:56 am

    Thanks, this article helped me a lot.

  • David January 16, 2016, 10:44 am

    About the localization of images, at least in Xcode 7 if you use the xcassets for storing your images for instance, there’s no way to localize from the GUI. ( at least I didn’t found one)

    Here’s a nice workaround

  • Ammad April 12, 2016, 8:22 am

    I followed your tutorial , everything is ok , after i change app and restart app , the language changes .But how do i change the app in runtime without restarting the app ? Am using swift . Please help , thanks !!!

Leave a Comment