0

I am creating an app that will be in English and Arabic. I am using my own localization system because I want to allow users to switch languages themselves from within the app and while the app is running (I am not aware of a way how to do this official Apple way). I would like to switch entire app to right-to-left when user picks arabic language, i.e. switch trailing and leading, text alignment etc.

Is this even possible?

EDIT: I am targeting iOS 7+

Lope
  • 5,388
  • 4
  • 30
  • 40

2 Answers2

1

If you need to change the direction of app to LTR & RTL then you could use that solution.

//FOR RIGHT TO LEFT
 UIView.appearance().semanticContentAttribute = .forceRightToLeft

//FOR LEFT TO RIGHT
 UIView.appearance().semanticContentAttribute = .forceLeftToRight

Hope this will solve your problem.

Reference: https://stackoverflow.com/a/48963618/8809657

Muhammad Abbas
  • 488
  • 5
  • 12
0

Yes, this is possible. From what I am understanding you want to move all of your components to the opposite side and also the text should be written from the right, right?

First of all, you have to set your language to the "AppleLanguage" key in user defaults:

NSUserDefaults.setObject(["ar"], forKey: "AppleLanguage")

Then you have to use auto layout. By default auto layout detects the region depending on the language chosen and when you've set leading and trailing spaces correctly, it will change the position of your text fields for example. If you want some of your components to stay on the same place, you have to use "left" instead of "leading".

Vasil Garov
  • 4,851
  • 1
  • 26
  • 37
  • 2
    I am already using autolayout and am aware of left/right leading/trailing stuff (not my first arabic app). I want the app to reflect language change immediatelly, just setting AppleLanguage doesn't do anything until restart. Is there any way how to reload/refresh views? – Lope Mar 30 '15 at 09:28
  • @Lope did you find a solution to this? – Ebtehal___ Aug 29 '18 at 10:15
  • @Ebtehal___ I don't think there is a solution, app should always follow device language and orientation. Doing anything else means getting yourself into a world of pain – Lope Aug 29 '18 at 11:02