AppleLanguages not taking effect after app restart (sometimes)

Hi, I'm calling UserDefaults.standard.setValue(["ru"], forKey: "AppleLanguages") to change the app language with my GUI, and then I ask the user to restart the app so the change will take effect.

The problem is sometimes, after setting the AppleLanguages UserDefaults, and restarting the app, nothing changes, and the app Locale.current.identifier stays the same.

Most of the time it works, but when it doesn't, I have to set the value and restart the app multiple times before it finally changes the language. I have no idea what the problem is related to since it appeared in one of the versions and nothing changed in the part of setting the language.

i've tried calling UserDefaults.standard.set instead of UserDefaults.standard.setValue, or calling synchronize(), but nothing worked.

Any help will be appreciated.

I'm calling UserDefaults.standard.setValue(["ru"], forKey: "AppleLanguages") to change the app language with my GUI

This is not a supported approach. AppleLanguages is an implementation detail, not something that’s considered API.

Taking a step back, there is no supported mechanism for your app to change its own language. That setting is the preserve of the user.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

I would recommend you redirect the user to your app’s settings, which has an entry to select the language. You can use openSettingsURLString for this purpose.

AppleLanguages not taking effect after app restart (sometimes)
 
 
Q