0

I'm trying to change on-the-fly the language of my app from ENGLISH to ARABIC and vice-versa.

In storyboard I've several horizontal constrains with fix values in leading property that must be solved as left for english language but as right for arabic language·

To change language on the fly I'm updating the value of "AppleLanguages" in User Defaults property with this code:

NSString* newCode = "ar";
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setObject:[NSArray arrayWithObjects:newCode, nil] forKey:@"AppleLanguages"];
[userDefaults synchronize];

After this, my texts are displayed in arabic, but my app continues solving "leading" as left (instead of right) and the preferred localization remains "en" instead of "ar".

NSString * currentLocalization = [NSBundle mainBundle].preferredLocalizations[0]; 

but when I stop/start the app, the values are the correct ones (app in arabic, "leading" as right and [NSBundle mainBundle].preferredLocalizations[0] == @"ar").

How can I do these changes without restart the app? Thanks in advance.

  • you can use http://stackoverflow.com/a/1746920/513286 solution the reload all the strings – cekisakurek May 06 '14 at 15:58
  • Thanks for the answer!. In my app the strings are displayed correctly (arabic or english). My problem is about storyboard constrains: an horizontal constrain of 20pt leading must be solved in arabic as 20pt right, but 20pt left in english. When I change from english to arabic on-the-fly, texts are translated fine but leading is wrong. After stopping-starting the app texts and leading are OK. – Miguel Angel May 08 '14 at 13:01

0 Answers0