Muneeb Rehman
Muneeb Rehman

Reputation: 67

Handle language change within iOS App in auto layout

In our app, we have to support English and Arabic languages but the language changing option is available within the app itself. Earlier we have handled the right to left and left to right language changes in code.

From iOS 9 onwards, designed the UI with auto layout will be handled this properly, while changing the language in iPhone settings.

As per my requirement, we have changed the language within the app and updated the "AppleLanguages" key directly. But the storyboard is not updating properly. Once I force quit the app and relaunch it, then it working fine.

I need clarifications in that, Is there any solution to change this (language within the app) without restarting the app? If No, for restarting the app, Can I show an Alert and quit the app (by using exit(0))? Is this will approved by app review team?

Upvotes: 1

Views: 2422

Answers (1)

Ahmad F
Ahmad F

Reputation: 31655

I need clarifications in that, Is there any solution to change this (language within the app) without restarting the app?

Yes, there is! if you are already handled changing the language by checking AppleLanguages global key and using Auto Layout, it should be easy to do such a functionality.

The solution would be switching the lproj bundle in order to get it localized without restarting the app, you should do Method Swizzling to achieve it.

I'd recommend to check Working with Internationalization and Localization in swift article, it will guides you clearly to do it from scratch (It works fine for me). After following along with it, the output should be similar to:

enter image description here


Also, you might want to check Localize-Swift library (Actually, I didn't use it).

Hope this helped.

Upvotes: 3

Related Questions