RTL support

Hi ,

I am currently building an IOS app that has both arabic and english content interspersed. I went through the documentation and I havea few questions or clarifications to ask.

1. Is there a way to set Application's Layout direction to arabic. is it okay to set

[[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObjects:@"ar", nil] forKey:@"AppleLanguages"]; [[NSUserDefaults standardUserDefaults] synchronize]; ? (In my application, a user can select around 2-9 languages )

2. I have two book items, if the book is arabic, I want that table cell to be from right to left , else i want it to be left to right. The only way I can think of right now is create different xibs, check if the language of my content is that of urdu/arabic, and pick that xib.

if([NSLocale characterDirectionForLanguage:@"ur"] == NSLocaleLanguageDirectionRightToLeft) {
NSLog(@"ur is Right to Left");

/

}

3. if I want to keep things simple and I was to just set label text direction, is there a way to autoturn the tableview cell? where image also moves accordingly?

thanks,

Deepiks

Replies

HI Deepiks,


What i understood from your question is, even though device language is something else you want your app tobe in Arabic? Force fully into Arabic.


Yes, you can force UI control to behave and follow RTL. From iOS 9, its possible (as far as i know) using UISemanticContentAttribute property.


https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UIView_Class/index.html#//apple_ref/swift/enumelt/UISemanticContentAttribute/c:@E@UISemanticContentAttribute@UISemanticContentAttributeForceRightToLeft


But its costly operation to go each and every UI Control in your app and change attribute/writingdirection manually.

Hi hshah,

Very much appreciate your prompt response. 🙂

Here 's what My app 's behavior is. I aggregate and show content of 20 different languages. User can select what is his preferred langauge and what are his other languages . Preferred language is the language in which the app's localization will be in .

Q1. Is it okay to save the languages in seperate NSUserDefault constant.


Q2. If user selects say Arabix as his language, the app to start with is Left to Right. In the Second screen he selects Arabic, so hence forth I want to show content of app in Right to Left. How do I go about doing this.

[[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObjects:@"ar", nil] forKey:@"AppleLanguages"]; [[NSUserDefaults standardUserDefaults] synchronize]; - I tried this and as u have also mentioned it looks like a costly operation for me. But then Is there a better way ?.


Q3. Worst alternative I have thought about is, create arabic specific xib's and storyboards and load them?


Q3.If I were to use IOS 9 UISemanticContentAttribute, I can still have this as my base sdk and set deployment target to 7.0?

It is highly recommended that you base the supported app language off of the user's selected language order in Settings, instead of selecting from a list of languages within your app. This is done automatically for you if you use our Internationalization API as expected. Setting AppleLanguages in NSUserDefaults is not recommended, and many things will not behave as expected. Your UI will not flip automatically in a right-to-left language, and other things like your formatters won't behave correctly without the constant requirement of additional setup.


Regarding UISemanticContentAttribute, you can keep your deployment target to 7.0 but you will need to wrap these calls inside an availability check. Your base SDK should always be the most recent one.