Locale.current reporting wrong language on device
@Romain The problem here is that you have not localized your app for French but only for English.
Go to the upper left blue file with the name of your app, select Project > Info and in the Localization area you will see "English - Development Language". Press + and choose French (fr).
That's it. Now you can use Locale.current and if the first language of a device (or simulator) is French, your app will show French currency format.
Based on @Romain's answer the forced unwrapping of first!
could be avoided by using the Locale.current.identifier
as fallback.
func getPreferredLocale() -> Locale {
guard let preferredIdentifier = Locale.preferredLanguages.first else {
return Locale.current
}
return Locale(identifier: preferredIdentifier)
}