Search code examples
iosswiftcalendardateformatter

SwiftUI Change language in new Foundation Formatters iOS 15


Hi everyone I keep having problems with the translation of the names of the months and days of my calendar ..

For iOS 14 I'm using

DateFormatter() (or Calendar.current.shortMonthSymbols)

for formatting the months of the calendar and for iOS 15 I'm using the new formatting found in Foundation

Date().formatted(.dateTime.year().month())

In both cases I cannot translate the names of days and months from English to Italian

Some time ago I did not have these problems because the translation was done directly from the language of the user's real device instead now since I installed iOS 15 on my real device the translations no longer occur automatically and I can't understand how I can solve it using a way elegant

Has anyone encountered these problems? any help?


Solution

  • Just make sure to set your calendar locale property:

    var cal = Calendar.current
    cal.locale = Locale(identifier: "it_IT")
    cal.shortMonthSymbols  // ["gen", "feb", "mar", "apr", "mag", "giu", "lug", "ago", "set", "