TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

Multi Language SwiftUI App

Forums > SwiftUI

Hi All, I hope someone can come up with a solution. I know it is possible and actually very easy to have a multilanguage app which uses system or system-configured language. Is it however possible to have some kind of setting inside the application which would enable user to select the application language in some kind of menu?

1      

First, you must create all the localizable files with the languages you want your app to handle.

Then, you can get the current language on device on first index in UserDefaults.standard.stringArray(forKey: "AppleLanguages"), then wherever you want you can set in your app the new language by setting "AppleLanguages" like

UserDefaults.standard.set(["es-MX"], forKey: "AppleLanguages")
UserDefaults.standard.synchornize()

1      

Once you have the localizable files of all the languages it supports

Why do you not just have a Button for them to change the laugauge of the app in Settings.

Button("Change Language") {
    if let url = URL(string: UIApplication.openSettingsURLString) {
        UIApplication.shared.open(url)
    }
}

This will then open the App Settings and in there is a PREFERRED LANGUAGE section which will set it for that app only. You will get all the other translation etc for free EG(Back button in NavigationView). App Settings

1      

Hacking with Swift is sponsored by String Catalog.

SPONSORED Get accurate app localizations in minutes using AI. Choose your languages & receive translations for 40+ markets!

Localize My App

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.