I am aware that iOS has the RTL (right to left) support for languages, and that by using leading and trailing constraints
I "tell" autolayout
to stack the elements according to the language orientation.
This all works great. If I want a constraint
to be fixed, I turn off respect language direction and there is no problem. However I need to make in app language selection, which will have LTR and RTL languages. How to signal the app to mirror the view to RTL and vice versa?
I know this could be done if I would iterate through constraints and change the leading/trailing to left right and vice versa, but is there any simpler solution for that?
App restart is also fine if needed!
Solution should support iOS 8.x +
Thank you

- 193
- 1
- 14
2 Answers
An app restart is required no other solution.
Apple guidlines suggests to the developers not to implement a language selection from inside the app. The developer should use the device selected language.
If you are asking for a way to restart the app. this also not possible. You can show an alert to the user ask him/her to restart. closing the viewcontrollers won't solve the problem either.
I usually do not turn on localisation for my app if I wanna implement an in-app langauge selection. unfortunately, I do all constraints by coding.
You can also have two layouts one for RTL and one for LTR. but, you also need to stop localisation, leading and trailing constraints will rune your layout. or you need to convert them all to left right manually. turning off inter localisation lets any added constraint to have left and right attributes and not trailing and leading.

- 23,815
- 10
- 63
- 101
-
I was thinking about reloading the storyboard inside container view on some kind of a "root" view controller, which would cause a re-draw of entire app. But I still don't know how to force the orientation, I can do it in iOS9.x but I don't see any other option then changing leading to left and trailing to right before view will appear when re-drawing the controller. – zevonja Mar 14 '16 at 18:19
-
Yes, at the end you must go and code. changing the leading and trailing to right and left by code depending on language looks good. – hasan Mar 14 '16 at 18:23
-
1+1 on hasan83's sentiment regarding in-app language switchers. This will be a very confusing user experience if your app does not automatically follow the system language at all time. – wakachamo Mar 14 '16 at 18:37
hasan83 answer is quite helpful still i would like to share what i have done to support both Right-To-Left and Left-To-Right language.
As hasan83 correctly pointed in the answer that 'An app restart is required' in order to change the UI Right-To-Left and Left-To-Right vice-versa.
So if you have to provide in app language selection at any cost, there is a way,
You have to add two storyboard for your app, one is for English and other one is for Arabic (in my case). Design the screen for English language first then copy and paste the same in Arabic language, and change the position of screen to make mirror view of English screen. Thats it for design perspective.
Edit your didFinishLaunchingWithOptions as below,
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//Load storyboard for the selected language
if ([kGetSelectedLanguage isEqualToString:kEnglish]) { //Load English Storyboard
// Get English Language Storyboard
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"English" bundle:nil];
// Create Navigation controller with RootViewController
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:[storyBoard instantiateViewControllerWithIdentifier:@"FindRestaurantsViewController"]];
// Set Windows RootViewController
[self.window setRootViewController: navigationController];
} else { //Load Arabic Storyboard
// Get Arabic Language Storyboard
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Arabic" bundle:nil];
// Create Navigation controller with RootViewController
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:[storyBoard instantiateViewControllerWithIdentifier:@"FindRestaurantsViewController"]];
// Set Windows RootViewController
[self.window setRootViewController: navigationController];
}
}
Add below code to the action of button where user changes the app language,
if ([kGetSelectedLanguage isEqualToString:kEnglish]) { //Load Arabic Storyboard
// Get Arabic Language Storyboard
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Arabic" bundle:nil];
// Create Navigation controller with RootViewController
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:[storyBoard instantiateViewControllerWithIdentifier:@"YourRootViewControllerIdentifier"]];
// Set Windows RootViewController
[appDelegate.window setRootViewController: navigationController];
[[NSUserDefaults standardUserDefaults] setObject:kArabic forKey:kSelectedLanguage];
[[NSUserDefaults standardUserDefaults] setObject: @"2" forKey:kSelectedLanguageId];
[[NSUserDefaults standardUserDefaults] synchronize];
} else { //Load English Storyboard
// Get English Language Storyboard
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"English" bundle:nil];
// Create Navigation controller with RootViewController
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:[storyBoard instantiateViewControllerWithIdentifier:@"YourRootViewControllerIdentifier"]];
// Set Windows RootViewController
[appDelegate.window setRootViewController: navigationController];
[[NSUserDefaults standardUserDefaults] setObject:kEnglish forKey:kSelectedLanguage];
[[NSUserDefaults standardUserDefaults] setObject: @"1" forKey:kSelectedLanguageId];
[[NSUserDefaults standardUserDefaults] synchronize];
}
Make sure you add the language change button to the RootViewController, otherwise it will not look good if you allow user to change the language anywhere in between the application flow.

- 4,158
- 2
- 16
- 27
-
Overriding language NSUserDefaults at runtime is not recommended and will still not work for system UI that your app presents, or formatters that your app uses. – wakachamo Mar 16 '16 at 19:57
-
Can you please explain what you mean by ' Overriding language NSUserDefaults at runtime is not recommended'. I have explained the way using which, one can allow their users to change the language inside app itself, it has nothing to do with system/OS language. I am currently working on a app in which i have handled the in app language change (as my client wants to give in app language change option to his users), and i have not faced any challenge in anything (System UI ..) so far (80% app is completed). I'll like to here more from you if you think that this is not recommended/wrong way. – Bharat Modi Mar 17 '16 at 04:28
-
My point is changing languages inside the app itself is not recommended. It will confuse your users because they expect the app to follow the system language at all times. You will run into issues and unexpected bugs when switching between LTR and RTL languages inside the app, and date formatters as well as any system UI (such as UIActivityViewController) will not respect the language that you set. Please don't do this. – wakachamo Mar 17 '16 at 06:00
-
1Your point is correct, but now a days many apps are providing this kind of functionality (Especially apps made for middle east people). And i'm not using any kind of localisation, what i'm doing is managing all view so that it will look like the selected language. Like label in English storyboard would have Left alignment whereas the same label would have Right alignment in Arabic, and that is perfectly fine, i'm just having two storyboard for two languages. – Bharat Modi Mar 17 '16 at 07:29
-
My point still stands that you're providing a subpar user experience for your users in the Middle East... it's confusing to have to manage a language for every single app you install. – wakachamo Mar 17 '16 at 18:28
-
In my opinion and many user thinks that it is an adequate experience to have in app language change feature. And what is there to manage about, this is not like every app has 10-100 languages to select from and he/she has to remember the selected language for each and every app. Its very simple, we are just providing 2 language that could be switched in app itself. – Bharat Modi Mar 18 '16 at 04:46
-
Lets take an example to make it more clear, if one of your friend from middle east come to your country (which has English language as a mother tongue), now you open the XYZ app in his phone and it has Arabic language selected previously, now is it good experience to go to the device setting, change the OS language to English and then again open the app and proceed, instead if you have in app language change feature you can simply change the language to English, use the app and simply change it back to Arabic, that's it. – Bharat Modi Mar 18 '16 at 04:46
-
In this total process of in app language change feature we are not breaking any of the Apple guidelines. – Bharat Modi Mar 18 '16 at 04:46
-
You are breaking guidelines because any system UI you present (like the share sheet) are not presented in the language the user chose, which presents an inconsistency. Furthermore, your goal should not be to provide "only 2 languages", it should be to provide as many as you can. The moment you expand your languages, this bad design becomes more and more apparent. – wakachamo Mar 18 '16 at 21:54