Goal to achieve
In a table, there is a column Date. The date should have a format based on the Locale of the user. Example:
- 24/01/2020 or 24/01/20 (I don't mind) for french users
- 01/24/20 for US users
Note: the app is (currently) only in English.
I have a Date
object which I would like to display to the user in the right format. For that, I suppose I have to use a DateFormatter, which has a locale
parameter. But I encounter an issue with the latter.
Problem
In a Xcode playground, on a Mac in French (Regio = BE) (but Xcode in English), the following code returns weird things.
Locale.current.regionCode // returns "BE"
Locale.current.languageCode // returns "en"
Locale.preferredLanguages[0] // returns "en"
Locale.current.identifier // returns "en_BE"
Locale.current.collatorIdentifier // returns "fr-BE"
Locale.current.collationIdentifier // returns nil
Note: french is one of the language in Belgium.
collatorIdentifier
interests me because it is the only one that detects that my mac is in French. But what is it? What is the goal of it and why does it return something significantly different than the others?