4

I have an app in iOS which I'm trying to localise for a RTL language. Obviously, the layout need to correspond with the language.

To get started, I'm trying to make to buttons in the bottom of one screen to change their order when opening the app with the rtl language locale set.

I use auto-layouts and I added constraints between the buttons and the view regarding trailing / leading horizontal view setting with the main view of the screen, which is what I understood should be done. Used the drag-n-drop blue line method for making the constraints. Also, I used the following code in my main as instructed by another thread:

#if TARGET == TARGET_AR
        NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
        [defaults setObject:[NSArray arrayWithObject:@"ar-SA"] forKey:@"AppleLanguages"];
        [defaults synchronize];
#endif

This still does not work, and the buttons stay where they were. Any suggestions on how to solve this?

Thanks

Lior Z
  • 668
  • 1
  • 9
  • 21

2 Answers2

1

I don't know where you got the recommendation to use the macro to determine the locale, but this is absolutely wrong.

What you are most likely missing is an actual RTL localization (it's great that you're using Base!). Select your project file in the file navigator and you should see something like this:

What you need to do is add an actual RTL localization. So click the '+' above the Use Base Internationalization checkbox and pick Arabic (ab) in the popup menu and then continue in the sheet that appears. If you build and run your app on a phone where Arabic is the preferred language, the constraints should flip as you expect!

lensovet
  • 5,490
  • 2
  • 23
  • 19
-2

I believe that the proper way to do this is to have separate storyboards for each locale, so that you can not only customize the text direction (RTL or LTR), but also use different languages for various UI Elements. You would obviously need to connect IBOutlets and IBActions for each storyboard, but it would be way more efficient and easier to implement then what you are proposing. Good luck!

user2105505
  • 686
  • 1
  • 9
  • 18
  • Redoing all of the outlets and actions sounds really not efficient. This can't be the best way. – Lior Z Apr 13 '14 at 21:02