Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flip layout on iPhone for RTL languages

Here is my issue :

I've localized my application in arabic. (It's actually slightly different than regular localization, as I have different targets, one for each language).

On the simulator, the view is properly flipped, thanks to Auto-Layout and the leading / trailing part of the constraints, but I can't seem to get the same result on a device. AutoLayout + RTL + UILabel text alignment shows an example of a flipped view on the simulator.

I've also found indication that it is supported in the Auto-Layout Guide : « The attributes leading and trailing are the same as left and right for left-to-right languages such as English, but in a right-to-left environment such as Hebrew or Arabic, leading and trailing are the same as right and left ». This lets me think that it is supposed to flip view, as it does on the simulator.

I use -AppleLanguages (ar_SA) in my scheme on the simulator, which thus flips the view, but fail to find the proper setting in the device itself to do the same thing. Setting the language and Region Format to Arabic doesn't seem to help much. That is on an iPhone 4S, iOS 7.0.4

TLDR: What setting should I change on an actual iPhone device to be in an « Arabic environment » and have a flipped view, or what am I missing so that it flips in the simulator but not on the device ?

like image 743
Nerkatel Avatar asked Mar 21 '23 03:03

Nerkatel


1 Answers

Ended up adding the following : 

int main(int argc, char *argv[]) {
    @autoreleasepool {
#if TARGET == TARGET_AR
        NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
        [defaults setObject:[NSArray arrayWithObject:@"ar-SA"] forKey:@"AppleLanguages"];
        [defaults synchronize];
#endif
        return UIApplicationMain(argc, argv, NSStringFromClass([SNFIdleDetectorApplication class]), NSStringFromClass([SNFAppDelegate class]));
    }
}

Though I do find this kind of ugly.

Edit : It may be interesting to note that when set to Arabic, the device shows @"ar" as the AppleLanguages first value, and not @"ar-SA". I guess flipping the view doesn't work with the @"ar" locale, although I'm unsure whether that's a bug, or if some arabic countries write LTR, thus making sense not to systematically flip the view.

like image 130
Nerkatel Avatar answered Apr 02 '23 04:04

Nerkatel