0

I have an xib file with multiple localization (.strings) files.

If I change the language option in the device's settings, the language of my xib changes accordingly.

I would like to be able to change the language within the app, so when I load a new view controller, I would like it to load the corresponding xib using the localization file of my choice instead of the one given by the device's preferences.

What's the best way to achieve this?

EDIT: I think you can achieve this by duplicating the xib file for each language, but I would like to have only one xib and use the desired language file to load its data.

Diego
  • 577
  • 4
  • 14
  • possible duplicate of [Manually loading a different localized nib in iOs](http://stackoverflow.com/questions/8712049/manually-loading-a-different-localized-nib-in-ios) – Misha Sep 27 '15 at 00:44
  • I think that method consists of building different versions of the xib for each language. I only have one xib file with multiple localizations – Diego Sep 27 '15 at 00:48
  • http://stackoverflow.com/questions/9416923/ios-how-to-change-app-language-programmatically-without-restarting-the-app?rq=1 you can see this question – Misha Sep 27 '15 at 01:02

1 Answers1

1

I had the same problem and just tested BundleLocalization suggested in this question. It works great and does exactly what you are looking for.

As mentioned on the git page, you need to reload the xib file for it to use the updated language.

Community
  • 1
  • 1
wolfrevo
  • 2,006
  • 2
  • 25
  • 32
  • Thanks! I had seen that method but it wasn't working, probably because I did not reload the xib properly. Now it's working perfectly. – Diego Sep 27 '15 at 16:34
  • Why do you want to do this? The one issue in that repository mentions system UI that still follows the same language. If you use this, you'll end up providing a really terrible mixed-language experience to all your users. – wakachamo Sep 28 '15 at 19:41
  • Given you are using system UI in the app, that's true. Many apps providing content (e.g. a cooking app) with multiple localizations, want to give users the ability to change the language independent of the system language. Many people use their devices in English, but when it comes to content they prefer their natural language. – wolfrevo Nov 01 '15 at 11:53
  • @wolfrevo How this code will translate the hard Coded Strings in the XIB. I mean if I don't take its reference variable then how will I be able to translate that text? – Developer Jun 07 '17 at 05:44