3
votes

I'm building an app that supports English and Arabic languages. So when the user switches the language into Arabic, the translation will switched into Arabic and the Layout would switched into RTL.

My question is what is the best practice in doing this? I've searched and asked a lot of devs regarding this one, and here are some of their answers:

  • Create 2 separate storyboards, one for English Layout, and the other one is for Arabic Layout.
  • When user clicks on the Language switcher, redirect them to the Phone System Settings and let them change their Region and Language because if the selected Region is Saudi Arabic, the app automatically does RTL.

I am not sure what's the best practice, kindly please enlighten me.

PS: I'm new to iOS Swift development.

Thanks! :)

2
If you use leading/trailing constraints in your storyboard rather than left/right (and leading/trailing is the default) then your storyboard will automatically adapt to rtl locale - Paulw11

2 Answers

3
votes

Your app should follow the system language as much as it can. iOS's entire API does this for you without you having to worry what the user's current language is. There is no need to check NSLocale, and that will give you inaccurate results depending on how many languages your app supports, anyway.

Use one single Storyboard, and use Auto Layout to define the constraints of your layout. Constraints that use Leading and Trailing properties flip automatically when displayed in a right-to-left language.

You should generally not need to use .ForceRightToLeft or .ForceLeftToRight explicitly as semanticContentAttributes.

The only thing you should make sure is that your project supports right-to-left localisations. The way this works is by adding languages when your project file is selected:

Screenshot of Xcode showing the project file being selected, highlighting the Localizations section, and the ability to add more supported languages within Xcode in your app

0
votes

I think somebody who would switch to arabic language in your app, already uses the Arabic Region and Language Settings.

So you might want to read out the Region let region = NSLocale.currentLocale().localeIdentifier or the language let language = NSLocale.preferredLanguages().first and automatically set your app to arabic language.

If the user don't use the Arabic Region and Language Settings he/she does this for a reason and in that case you shouldn't open the settings but do the RTL yourself instead of forcing the user to change the device settings just to use your app.