1

I use these methods

[[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObject:@"ar"] forKey:@"AppleLanguages"];
[[NSUserDefaults standardUserDefaults] synchronize]; 

to force my app to change its localization during run time (when the user taps a button which simple calls these methods) and it works perfectly, however, these methods are not sufficient to switch the whole XIB to the new language (which is in my case, Arabic language), giving that I have one XIB named HomeViewController.xib that opens as a directory in XCode, a directory of two files: HomeViewController.xib (English) and HomeViewController.xib (Arabic) each file has its own layout according to language (for ex. Arabic xib has right to left controls layout ..), i've tried to call removeFromSuperView for every control on the current controller and then call addSubView for the controls, but nothing has changed, the app still displays the english XIB.

how can I let my app to change its XIB to the correct localized one at run time when that language button tapped.

p.s. when I change the whole simulator localization in system settings, the app works as expected, i.e. it displays the correct localized XIB.

JAHelia
  • 6,934
  • 17
  • 74
  • 134

2 Answers2

2

At run time it is decided which xib will be loaded, as you say that when you change the simulator setting then you are able to see the arabic screen.

So decision of xib is based on what you have given in your user defaults, then it check for locale and corresponding to that locale xib is loaded.

PeeHaa
  • 71,436
  • 58
  • 190
  • 262
rishi
  • 11,779
  • 4
  • 40
  • 59
  • but i set the object @"ar" in user defaults, so it must load the correct xib when I try to do removeFromSuperView and addSubView – JAHelia Dec 25 '11 at 11:32
  • That object is set for Arabic locale and default locale is en. So as soon as you launch your app it loads en xib. – rishi Dec 25 '11 at 11:39
  • I created a new nib at run time like this: HomeViewController *homevc = [HomeViewController alloc] initWithNibName: @"HomeViewController" Bundle: nil]; then I added this view controller to a navigation controller then I add this nav controller as a subview to the current view controller. – JAHelia Dec 25 '11 at 11:45
  • That is what it searches at runtime- If Locale is english then it goes to english xib file in bundle and if locale is arabic then goes to arabic folder. It creates a runtime binding. – rishi Dec 25 '11 at 11:51
  • so does that mean it's impossible to switch to the desired localized xib at runtime ? is there a workaround for this issue ? I saw many apps with a switch language button, when this button is pressed the UI completely changes to match the new language. – JAHelia Dec 25 '11 at 12:55
-1

some fellow developer almost solved the issue, please have a look at this sample app: https://rapidshare.com/files/3434929956/LangSwitch.zip it switches the whole XIB on the fly from Arabic to English and vice versa, what i'm stuck at right now is : I need this sample app to be tabbed, i.e. with a tab bar controller with two tabs, each tabs contains one view controller (you know, the usual way), anybody solves this problem I'd be sooo grateful to him/her ... waiting for your help guys ...

JAHelia
  • 6,934
  • 17
  • 74
  • 134
  • -1 for posting an answer with a link that was very likely to expire in the future and generally giving no other information. – NikosM Oct 29 '14 at 22:01