4

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 ?

Community
  • 1
  • 1
Nerkatel
  • 1,805
  • 16
  • 25

2 Answers2

4

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.

Nerkatel
  • 1,805
  • 16
  • 25
  • Wow, do you mean that changing the device's language setting to Arabic (General > International > Language > العربية) does not do the exact same thing as those 3 lines of code? – Clafou Apr 08 '14 at 12:33
  • @Clafou He said, that he has one target per language, so he maybe wants to set the language for each target manually. – lootsch Apr 08 '14 at 12:44
  • @lootsch He also says in his last 2 paragraphs that changing his international settings to Arabic doesn't result in the flipping on a device. But yes, I suppose by doing the same thing in code he can force flipping in all cases. What I don't get is why it doesn't work (as he claims) if he just runs with the device set to Arabic. – Clafou Apr 08 '14 at 14:15
  • @Clafou This totally baffles me but yes, I can't seem to get it to work on an actual device, when only setting the language in Settings > General > International > Language > Arabic. Tried to reboot after changing the language too, with the same end result though. And yet, these three lines of code do the trick. I have no explanations for this. – Nerkatel Apr 08 '14 at 14:50
  • That's so weird. Those 3 lines should have no effect when the language is already set to ar-SA! Would be interesting to confirm that the AppleLanguages value is indeed `@[@"ar-SA"]` (shorthand for `[NSArray arrayWithObject:@"ar-SA"]` by the way) when running on the Arabic device – Clafou Apr 08 '14 at 15:52
  • It has `@"ar"` (and a whole bunch of other languages, but `@"ar"` is the array `firstObject`) instead of `@"ar-SA"` when running on the device, set to Arabic language, the first time I launch the application, before overwriting the value myself. – Nerkatel Apr 08 '14 at 16:17
3

Hope it's not too late, I had a similar problem, you can check this: https://stackoverflow.com/a/25380873/2633295

Community
  • 1
  • 1
Raz
  • 2,633
  • 1
  • 24
  • 44