1
extension UnitSpeed {
    static var kilometersPerMinute: UnitSpeed {
        return UnitSpeed(
            symbol: "km/min",
            converter: UnitConverterLinear(coefficient: 16.666666666667)
        )
    }
}

let formatter = MeasurementFormatter()
formatter.unitStyle = .short
formatter.locale = Locale(identifier: "ru_RU")

print(formatter.string(from: UnitLength.kilometers)) // prints км
print(formatter.string(from: UnitDuration.minutes)) // prints мин
print(formatter.string(from: UnitSpeed.kilometersPerHour)) // prints км/ч
print(formatter.string(from: UnitSpeed.kilometersPerMinute)) // prints km/min

I created a custom UnitSpeed. Is it possible to localize the symbol of this unit?

Alexey Golikov
  • 652
  • 8
  • 19
  • Add it in the `Localizable.strings` file? – Sweeper Jul 11 '19 at 13:03
  • May the system localize this symbol since it already has translations for kilometers and minutes? – Alexey Golikov Jul 11 '19 at 13:16
  • Localisation is not simply replacing `km` with whatever `km` translates to, and `min` to whatever `min` translates to. There will be some locales out there that breaks this rule. – Sweeper Jul 11 '19 at 13:19

0 Answers0