How can I generate cardinal numbers(One, Two, Three)
using NumberFormatter
in Swift using Locale settings.
For example, I am able to convert 1 minute -> One minute
using English Locale
settings. But for Norwegian it should be Et minutt, While it translates to En minutt which is wrong.
Norwegian translation for One
is En
but when we use it in some sentence, sometimes it should be Et
.
Here is sample of my code.
let measurement = Measurement(value: 1, unit: UnitDuration.minutes)
let measurementFormatter = MeasurementFormatter()
measurementFormatter.unitStyle = .long
measurementFormatter.locale = Locale(identifier: "nb_no")
let formatter = NumberFormatter()
formatter.locale = Locale(identifier: "nb_no")
formatter.numberStyle = .spellOut
measurementFormatter.numberFormatter = formatter
let result = measurementFormatter.string(from: measurement)
Output:
én minutt
Expected Output
et minutt
Formatters
so that my solution can be a generic one. – Lydie