UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

How can i change app language on the fly without the need to restart the app ?

Forums > SwiftUI

Hi everybody

i searched a lot on how to change app language and found that it reauires the restart of the app. Can any body give a solution on how to do that in swiftui

Thanks

3      

Restarting the app? I don't think this is possible because you can't run code when your app doesn't run.

3      

It can be done but I dont think it should. One common approach is to add link to system settings for your app which will launch Settings and open the section for the app in question. Here user can choose from the available language, and when they return to the app, iOS will do sort of a restart to load the new localizations.

Or you could have this settings in the app and after user changes language option, then manually reconfigure all texts in the app to be in the new language.

This is how you get system settings URL - https://developer.apple.com/documentation/uikit/uiapplication/1623042-opensettingsurlstring which can be opened for example with UIApplication.shared.openURL or the SwiftUI way is here: https://www.hackingwithswift.com/quick-start/swiftui/how-to-open-web-links-in-safari

4      

You can change the language even without restarting the app. Check out this github repo https://github.com/anoop4real/LanguageSettings

3      

TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!

Find out more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.