Sunday, 17 April 2011

Advance Localization in ios apps

Localization in ios is usually done using this way. But the main problem with this approach is that to view the application in other language the language has to be changes from the settings of the ios device.
In this post i will present an approach in which you can set the language of the application from within the application.
but before starting lets understand the current localization procedure. we use NSLocalizedString() to get the localized version of any string, which acts as a key to match the key value pair in the localized version of Localizable.strings file.
what infact NSLocalizedString() calls in background is [[NSBundle mainBundle] localizedStringForKey:(key) value:@"" table:nil] where [NSBundle mainBundle] is the default main bundle.
The trick to use is to get the value of localizedStringForKey from the bundle of your choice. So what we will do is that depending on the language selected we will select the specific bundle and use the [[NSBundle mainBundle] localizedStringForKey:(key) value:@"" table:nil] to get the localized value of the string.
so lets get started

1- Localize your application using the method describe here. i recommend using this method just so that you can use "genstrings" to create string table.
2- put the localized version of string values in the localized Localizable.strings.
3- Replace the NSLocalizedString with any function name of your choice, i will be using  languageSelectedStringForKey .
4- Write a method definition and implementation of -(NSString*) languageSelectedStringForKey:(NSString*) key where it is accessible in the scope where the localized string is needed.
5- in the languageSelectedStringForKey method select the appropriate bundle depending on the language selected and call [[NSBundle mainBundle] localizedStringForKey:(key) value:@"" table:nil] on the bundle.
for NSString *path= [[NSBundle mainBundle] pathForResource:@"fr" ofType:@"lproj"];  
NSBundle* languageBundle = [NSBundle bundleWithPath:path];
and then get the string like this
NSString* str=[languageBundle localizedStringForKey:key value:@"" table:nil];
str here is the localized string.

again all which i described above have been put in this code and i have placed it on github for any reference.


  1. This is a great post .
    It help me solved my problem..

  2. Wow, thank you so much! Finally a solution that works just like I want it! I've condensed your main function down to the essentials in this pastie:

  3. how to use this method to localize a button text?

  4. You can also set the text of button programatically
    [myButton setTitle: @"myTitle" forState: UIControlStateNormal];

    here set the @"myTitle" using the above method.

  5. It was very useful for me dude!
    Thank you very much!

  6. Why bother when automates the entire localization for you?

  7. Hello, how are you?
    His method works, however I have a doubt. How do I get the whole application to be "located", I say, we have a variable LocalizedText.h, but if I have another view? How do I call the method - (NSString *) languageSelectedStringForKey: (NSString *) key in the other views?

    I tried putting this in a separate class and could not.

    My mail is:


  8. Hi Adriano,

    You can make a singleton. This singleton will implement the "languageSelectedStringForKey" method. Which than you can call from anywhere within your project.
    Read here how to make a singleton class.

  9. Very good, that fasten. Thanks very much.

  10. Thank you for the post. Are you aware of how to switch between localized xib files? For an example if you compare Arabic and English languages there is a huge difference of rendering the content. Arabic content should be displayed from right to left. So we need to create the user interface specific to it. How can we switch to the Arabic specific localized XIB user interface upon clicking the language button?

  11. @Amilla In that case above solution may not work for you, Make two nibs and switch between them using
    + (BOOL)loadNibNamed:(NSString *)aNibName owner:(id)owner

    More description at:

    1. Thank you very much for your reply.

  12. sorry i can't get it .. how to use loadNibnamed to load different nibs using your methods? can you give me a little more details

    1. ok i got it myself :D :D

      - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
      self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
      if (self) {
      NSString *path= [[NSBundle mainBundle] pathForResource:@"ar" ofType:@"lproj"];
      NSBundle* languageBundle = [NSBundle bundleWithPath:path];
      NSArray *nibObjs = [languageBundle loadNibNamed:@"MainViewController" owner:self options:nil];
      UIView *aView = [nibObjs objectAtIndex:0];
      self.view = aView;
      return self;

      i put it here for others when they reach your page :D

  13. This comment has been removed by the author.

  14. but i found a problem in this approche that i can't find why it happens .. when i used this approach of calling this in initWithNibName the viewDidLoad is never get called ..why is that..

  15. Thanks for the post..I;m seeing that UIKeyboard is not comes in english..which should not be the case..could you check this out..thanks

  16. Unfortunately there is no way to control the keyboard language programmatically.

  17. Or you can use an online localization tool such as It does its job perfectly well.

  18. What will be happen with jailbreak for getting more apps in the iPhone devices?
    read more

  19. The method described in isn`t available anymore... Can you give us a hint?

  20. Nice post, thanks for sharing. Any idea how could I have the same functionality with the Storyboard's strings?

  21. This translation tool could help a lot in the iOS localization process: It offers possibilities of automatic translation for strings and also of collaborative translator work. It has API and Github integration also.

  22. How to localization more than one languages. ?
    can i localization 5 languages ?

  23. thanks a lot sir...superb article

  24. There is another interesting service that provides sdk and online update for ios apps translation:
    You can manage you localisation files without the need to think about which version of the app you're updating. You also don't need to recompile the app each time you add a new language.


  25. Thanks for sharing information.
    recharge offers
    videocontelecom offers new Customers the proposition will be available on Plan voucher (PV) priced at Rs 76, offering All Local Calls at 25P/min only for 6 months including Rs 63 Talk time; 1050 MB data for 3 month and 100 SMS free/day, with first 2 SMS of the day chargeable at rack rate only in Haryana.

  26. Nice it seems to be good post... It will get readers engagement on the article since readers engagement plays an vital role in every blog.. i am expecting more updated posts from your hands.
    Mobile App Development Company in Chennai
    Android app Development Company in Chennai
    ios app development Company in Chennai

  27. It's interesting that many of the bloggers your tips helped to clarify a few things for me as well as giving.. very specific nice content. And tell people specific ways to live their lives.Sometimes you just have to yell at people and give them a good shake to get your point across.
    Mobile App Development Company
    Android app Development Company
    ios app development Company
    Mobile App Development Companies

  28. Where can I get the latest post on this.

  29. Thanks for posting useful information.You have provided an nice article, Thank you very much for this one. And i hope this will be useful for many people.. and i am waiting for your next post keep on updating these kinds of knowledgeable things...Really it was an awesome article...very interesting to read..
    please sharing like this information......
    Android training in chennai
    Ios training in chennai

  30. Pretty article! I found some useful information in your blog, it was awesome to read, thanks for sharing this great content to my vision, keep sharing..
    Android App Development Company

  31. You have provided an nice article, Thank you very much for this one. And i hope this will be useful for many people.. and i am waiting for your next post keep on updating these kinds of knowledgeable things...
    iOS App Development Company
    iOS App Development Company

  32. I wondered upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I’ll be subscribing to your feed and I hope you post again soon.

    <Fitness SMS
    Fitness Text
    Salon SMS
    Salon Text
    Investor Relation SMS
    Investor Relation Text
    Mobile Marketing Services
    mobile marketing companies
    Sms API

  33. great and nice blog thanks sharing..I just want to say that all the information you have given here is awesome...Thank you very much for this one.
    web design Company
    web development Company
    web design Company in chennai
    web development Company in chennai
    web design Company in India
    web development Company in India

  34. This is excellent information. It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...
    Mobile Marketing Service
    Mobile Marketing Companies
    Texting API
    Sms API
    sms marketing

  35. IOS is my dream. I hope that I can learn this, but I think it's hope, not more than. Now i work in a company that provide services for IOS development. It also provide outsourcing software services to global market.

  36. Finally I found the solution that work just like I want. Thanks for the post. iPhone Application Developers

  37. This is one awesome blog article. Much thanks again ios app development online course

  38. good post.the given information is very helpful.keep posting like this.Best Mobile Applications Company in Hyderabad