Localization

Localization in iOS, sometime we want out app to change its UI/Language according to the location i.e Hindi in India, English in US. For doing this we have to put a little extra effort and our app is good to go. We will continue Localization  we must know whats the difference between these 2 terms.

Localization is merely translating the app’s user interface and resources into different languages.

Internationalization is the process of designing your app for international compatibility. For example.

  • Handle text input, output processing in the user’s native language.
  • Handle different date, time and number formats.
  • Utilize the appropriate calendar and time zone for processing data.

 

Initiating the process : separating texts from the code

Create the String file Go to File > New > File. Choose Strings File under the Resource subsection.

Localization/Internationalization in iOS

Name the file Localizable.strings, its standard. In this file you have to define the text with respect to key like key content pair, you have to hardcode it all for all languages :

Add different language support by selecting clicking on your project Name the click on Project in the next pane not Target. Click in the + icon below Localization section and select your required language.

Localization/Internationalization in iOS
#Note : UI of the app will automatically changes to right to left if Arabic language support added.

Select the files you want to make localize.

Localization/Internationalization in iOS

#Note : Localize your string file too, click on your string file and on your right hand side in your Xcode in attribute inspector there is a button name Localize.

Showing the Localized text on UI elements.

 

Showing the Localized text on static elements.

For your static elements of storyboards you can assign text to them by using their ID in Main.String(Language) individually.

Localization/Internationalization in iOS

 #Note you have to do this for your individual language storyboard.

Some Other Formatings (if required)

Currency Formatting : will display currency according to Locale

 

 Name Formatting Use PersonNameComponents class.

 

 Date formatting: Always try to use default apple time formatting style.

 

Changing language of iPhone/Simulator for testing

You can either your iPhone language or just edit project schema for testing out your Localization project.

  • Settings app > General > Language & Region > iPhone Language.
  • Select Project > Edit Schema > Run > Option > Application Language.

Localization/Internationalization in iOS

Manually Changing language within App.

Showing your preferred language irrespective of your localewe have to create our own method. Ask user for his preferred language save your selected language to UserDefaults or data base. 

As simple as that.

Localization/Internationalization in iOS
Localization in iOS

Today we learn how to do Localization in Swift3 using Xcode 8.1. If you have any question feel free to comment. You can download sample project from here.

Happy Coding 🙂

3 Comments

Add a Comment

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.