Change localization of UIDatePicker in iOS 14

In my application users can change localization on the fly without restarting, and I have a date picker with inline preferred style, but it always displays on default language, if I set programmatically locale in 'en' or 'he' - changed the only month but days of the week still display on default language, how I can resolve this issue?

P.S. I tried to change locale in this way:
UserDefaults.standard.set(['he'], forKey: "AppleLanguages")
UserDefaults.standard.synchronize()
But it's work only after relaunch of the app.

So, how I can change the locale of days of the week on my locale without relaunch the app?
Answered by Claude31 in 674420022
Thanks for feedback, I was sure it did work… As it is not possible to edit message, I duplicate the answer.

You can change localization on the fly without restarting (works only over iOS 13.)

You should do it by opening the app settings and let user select the language for the app:

Code Block
func openSettings() {
guard let settingsUrl = URL(string: UIApplication.openSettingsURLString) else {
return
}
if UIApplication.shared.canOpenURL(settingsUrl) {
UIApplication.shared.open(settingsUrl, completionHandler: nil) // { (success) in
}
}


users can change localization on the fly without restarting

You should do it by opening the apps settings and let user select the language :
Code Block
func openSettings() {
guard let settingsUrl = URL(string: UIApplication.openSettingsURLString) else {
return
}
if UIApplication.shared.canOpenURL(settingsUrl) {
UIApplication.shared.open(settingsUrl, completionHandler: nil) // { (success) in
}
}


in this way you will change language for all device, but in my case I should change language for only my application
No, you access to your app settings only.
Changing the language using a UserDefaults value like you showed is not supported, and creates issues like this. You should direct users to change the language for your app (which is not the same as the language set for the device) in Settings, as @Claude31 is suggesting.
@edford
I do it in all apps now. That's very convenient. It allows for a very fast language switching.
The only caveat of course, it that when you open settings from iOS, the app settings are not localized.

Nevertheless, there is something not possible here. Here is the use case.
  • I work or play with s.o. on the iPad. I speak french, he speaks spanish.

  • When I face the iPad, app is in french.

  • When I lean to him, view rotates and now it's spanish.

Wouldn't it be cool ?
@Claude31, on iOS 14.5, xCode 12.5 your suggestion open general settings, and if I change language I changed for iPad, but not for my application (checked on simulator)
I tested on 12.4 and 14.4.
With this code I land in Settings page for the app, with Preferred language entry to select.

So I cannot tell for sure on 12.5, but I'm surprised.
Have you a way to compare on 12.4 and 14.4 ?
I make double check and it's worked correctly)
thanks a lot for your answer)
For future who will have the same issue - please check this Apple likn (this is the new way to change the language on the fly in your application, but only for iOS 13 and higher)

@Claude31 please, attach this link https://developer.apple.com/news/?id=u2cfuj88 to your first message and add restriction for iOS 13 and higher and I will mark it like answer.

Accepted Answer
Thanks for feedback, I was sure it did work… As it is not possible to edit message, I duplicate the answer.

You can change localization on the fly without restarting (works only over iOS 13.)

You should do it by opening the app settings and let user select the language for the app:

Code Block
func openSettings() {
guard let settingsUrl = URL(string: UIApplication.openSettingsURLString) else {
return
}
if UIApplication.shared.canOpenURL(settingsUrl) {
UIApplication.shared.open(settingsUrl, completionHandler: nil) // { (success) in
}
}


Change localization of UIDatePicker in iOS 14
 
 
Q