Hey @etrality! Thanks for the clarification, I just tested this and it seems to work:
If you modify the `format` method from that Stack Overflow post to include a specific locale for the calendar, this translation will work as expected. Here’s my new `format` method I’m using:
static func format(unit: NSCalendar.Unit, numberOfUnits: Int) -> String? {
var calendar = Calendar.current
calendar.locale = Locale.current
var dateComponents = DateComponents()
dateComponents.calendar = calendar
componentFormatter.allowedUnits = [unit]
switch unit {
case .day:
dateComponents.setValue(numberOfUnits, for: .day)
case .weekOfMonth:
dateComponents.setValue(numberOfUnits, for: .weekOfMonth)
case .month:
dateComponents.setValue(numberOfUnits, for: .month)
case .year:
dateComponents.setValue(numberOfUnits, for: .year)
default:
return nil
}
return componentFormatter.string(from: dateComponents)
}
When I print the period method like this:
print(package.product.subscriptionPeriod?.localizedPeriod())
An Optional was printed to the console:
1 Jahr
Let me know if that works for you, too!