Post

Replies

Boosts

Views

Activity

Reply to Get the word "Month", "Day", "Week" localized
Following up my previous comment (still being approved) A more type-safe version: enum UnitSymbol: String { case month case week case day } func localizedUnit(for unitSymbol: UnitSymbol, locale: Locale) -> String { let numberFormatter = NumberFormatter() numberFormatter.notANumberSymbol = "" let formatter = MeasurementFormatter() formatter.unitStyle = .long formatter.numberFormatter = numberFormatter formatter.locale = locale return formatter.string(from: Measurement(value: .nan, unit: Unit(symbol: unitSymbol.rawValue))) }
Oct ’24
Reply to Get the word "Month", "Day", "Week" localized
I managed to do it using this: func localizedUnit(for unit: Unit, locale: Locale) -> String { let numberFormatter = NumberFormatter() numberFormatter.notANumberSymbol = "" let formatter = MeasurementFormatter() formatter.unitStyle = .long formatter.numberFormatter = numberFormatter formatter.locale = locale return formatter.string(from: Measurement(value: .nan, unit: unit)) }
Oct ’24